我试图通过使用默认 httpClient 的 Web 服务调用获取 xml 响应,但由于 response.getEntity().getContent() 中出现错误消息而无法这样做。通过我的响应代码 200 comming,line String veraible 总是会出现。DefaultHttp 客户端对象是从另一种方法创建的
这是我的代码-
try {
HttpPost post = new HttpPost(tmsURL);
post.setHeader("Content-Type", "text/xml;charset=utf-8");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair(METHOD_PARAM, method));
nameValuePairs.add(new BasicNameValuePair(XML_PARAM, xml));
UrlEncodedFormEntity entity_st=new UrlEncodedFormEntity(nameValuePairs,"UTF-8");
post.setEntity(entity_st);
HttpResponse response = client.execute(post,localcontext);
responseCode = response.getStatusLine().getStatusCode();
if (responseCode == HttpStatus.SC_OK) {
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.info("Exception occured in httpClientSendRequest() : "
+ printStackTrace(e));
result = buildXmlErrorMessage("", e.getMessage(), "");
} finally {
// post.releaseConnection();
}
please help me if anybody have any solution to solve the issue