解析 post 方法的响应
我正在将数据发布到服务器,并以响应的形式返回发布数据...... 我使用这段代码
PostMethod post = new PostMethod(this._serverUrl);
InputStream is=null;
is = new ByteArrayInputStream(postData.getBytes("UTF-8"));
post.setRequestEntity(new InputStreamRequestEntity(is));
post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);
String response="";
response = post.getResponseBodyAsString();
我已经使用 commons apache httpclient 来发帖...... 在这里我得到的响应是
03-31 17:53:49.192: INFO/Response(2237): <?xml version="1.0" encoding="UTF-8"?>
03-31 17:53:49.192: INFO/Response(2237): <AndroidGame>
03-31 17:53:49.192: INFO/Response(2237): <Result>0</Result>
03-31 17:53:49.192: INFO/Response(2237): <ErrorCode>509</ErrorCode>
03-31 17:53:49.192: INFO/Response(2237): <ErrorMsg>You are using wrong Super Password</ErrorMsg>
03-31 17:53:49.192: INFO/Response(2237): </AndroidGame>
但我需要得到字符串中的响应...我无法在单个字符串中获得响应...它是成块的...任何人都可以帮助我吗
i am posting the data to a server and i get the post data back in form of response...
I use this code
PostMethod post = new PostMethod(this._serverUrl);
InputStream is=null;
is = new ByteArrayInputStream(postData.getBytes("UTF-8"));
post.setRequestEntity(new InputStreamRequestEntity(is));
post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
HttpClient httpclient = new HttpClient();
int result = httpclient.executeMethod(post);
String response="";
response = post.getResponseBodyAsString();
I have used commons apache httpclient to do posting....
here i get response as
03-31 17:53:49.192: INFO/Response(2237): <?xml version="1.0" encoding="UTF-8"?>
03-31 17:53:49.192: INFO/Response(2237): <AndroidGame>
03-31 17:53:49.192: INFO/Response(2237): <Result>0</Result>
03-31 17:53:49.192: INFO/Response(2237): <ErrorCode>509</ErrorCode>
03-31 17:53:49.192: INFO/Response(2237): <ErrorMsg>You are using wrong Super Password</ErrorMsg>
03-31 17:53:49.192: INFO/Response(2237): </AndroidGame>
But i need to get the response in String.... I am not able to get the response in a single string... it comes in chunks... Can anyone help me in this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这样做(我已经统一了我使用的不同方法的代码,所以它可能有点混乱):
I do it this way (Ive united code from different methods I use so it could be a bit messy):