我試圖從我的android應用程序訪問SOAP服務。訪問SOAP服務僅適用於Android模擬器
我測試用http://www.requestmaker.com/所以我結束了這個請求我的要求:
請求的頭部信息:
POST /WebserviceHCX.asmx HTTP/1.1
Content-Type: text/xml;charset=UTF-8
SOAPAction: hcxwords/installAcknowledge
Host: webservice.hcxwords.eu
Accept-Charset: utf-8
Accept: text/xml,application/text+xml,application/soap+xml
Content-Length: 382
請求數據:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<installAcknowledge xmlns="hcxwords">
<deviceID>test</deviceID>
<refCode2></refCode2>
</installAcknowledge>
</soap:Body>
</soap:Envelope>
由於這我只是在http://www.requestmaker.com/工作得很好(200 OK)想在我的Android應用程序中做同樣的事情。
final String SOAPRequestXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><installAcknowledge xmlns=\"hcxwords\"><deviceID>"+deviceID+"</deviceID><refCode2>"+refCode2+"</refCode2></installAcknowledge></soap:Body></soap:Envelope>";
String url = "http://webservice.hcxwords.eu/WebserviceHCX.asmx";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.addHeader("Content-type", "text/xml;charset=UTF-8");
httppost.addHeader("SOAPAction", "hcxwords/installAcknowledge");
httppost.addHeader("Host", "webservice.hcxwords.eu");
httppost.addHeader("Accept-Charset", "utf-8");
httppost.addHeader("Accept", "text/xml,application/text+xml,application/soap+xml");
StringEntity se;
try {
se = new StringEntity(SOAPRequestXML, HTTP.UTF_8);
se.setContentType("text/xml;charset=UTF-8");
se.setContentEncoding("utf-8");
httppost.setEntity(se);
// Execute HTTP Post Request
BasicHttpResponse httpResponse =
(BasicHttpResponse)httpclient.execute(httppost);
return httpResponse;
} catch (ClientProtocolException e) {
e.printStackTrace();
throw new IllegalStateException("ClientProtocolException ");
} catch (IOException e) {
e.printStackTrace();
throw new IllegalStateException("IOException ");
}
這通過我的Nexus 4是(404)和我的三星平板電腦它拋出IOException異常的工作在我的仿真器(200 OK)大:
IOException異常:無法解析主機「web服務。 hcxwords.eu「:沒有與地址相關聯的主機名
模擬器與服務位於完全不同的網絡上。 – Semanticer
是的,但仿真器可能位於同一防火牆後面,在這種情況下,它可以解析名稱。顯然,設備無法解析名稱。 – EJK
嘗試更改您的URL,以便它通過IP地址而不是通過名稱引用服務器。 – EJK