【发布时间】:2013-08-02 13:34:18
【问题描述】:
代码:
String response ;
try {
final String SOAP_ACTION = "http://tempuri.org/myAction";
final String URL = "MYURL";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(URL);
String bodyOut = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">"
+ " <soapenv:Header/>"
+ " <soapenv:Body>"
........ MY Data.......
+ " </tem:Login>"
+ " </soapenv:Body>" + "</soapenv:Envelope>";
StringEntity se = new StringEntity(bodyOut, HTTP.UTF_8);
//StringEntity se = new StringEntity(request1, HTTP.UTF_8);
se.setContentType("text/xml");
httpPost.addHeader("SOAPAction", SOAP_ACTION);
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity resEntity = httpResponse.getEntity();
response = EntityUtils.toString(resEntity);
if (response != null) {
Log.i("Response", "" + response);// this is not being printed
Log.i("test response", "not null");// this is being printed
}
else
Log.i("Response", "null");
} catch (Exception e) {
e.printStackTrace();
}
没有例外,但是:Log.i("Response", "" + response);// this is not being printed
LogCat:
08-02 19:04:51.929: I/test response(20413): not null
【问题讨论】:
-
记录
httpResponse.getStatusLine()。这表示您的消息无法处理。 -
@Raghunandan 谢谢 :),你说得对,我收到了
HTTP/1.1 400 BadRequest -
stackoverflow.com/questions/8087515/…。检查这个接近你的错误状态
-
@Raghunandan 当我尝试使用
se.setContentType("application/soap+xml");而不是se.setContentType("text/xml");时出现错误请求 -
很高兴知道,甚至更好,因为您发布的解决方案将帮助其他人接受它
标签: android soap httpresponse soap1.2