我正在使用follwing代碼來發送SOAP請求。發送SOAP請求的問題
String str = new StringBuilder("POST /WrenchTelLink/WrenchENTService.asmx HTTP/1.1\n")
.append("Host: 59.160.183.14\n")
.append("Content-Type: text/xml; charset=utf-8\n")
.append("Content-Length: LLLLLL\n")
.append("SOAPAction: \"http://WrenchGlobal/GetToDoList\"\n ")
.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>")
.append("<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/\">\n")
.append("<soap:Body>\n")
.append("<GetToDoList xmlns=\"http://WrenchGlobal/\">\n")
.append("<viPeriod>IIIIII</viPeriod>\n")
.append("<vsUserID>SSSSSS</vsUserID>\n")
.append("</GetToDoList>\n")
.append("</soap:Body>\n")
.append("</soap:Envelope>\n").toString();
String temp = str.replaceAll("LLLLLL",Integer.toString(str.length()))
.replaceAll("SSSSSS",ph).replaceAll("IIIIII",Integer.toString(period));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try
{
StringEntity se = new StringEntity(temp,HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setHeader("Content-Type","application/soap+xml;charset=UTF-8");
httppost.setEntity(se);
BasicHttpResponse httpResponse = (BasicHttpResponse)httpclient.execute(httppost);
if(httpResponse.getStatusLine().toString()!="")
Toast.makeText(TelLinkActivity.this, httpResponse.getStatusLine().toString()
, Toast.LENGTH_SHORT).show();
else
Toast.makeText(TelLinkActivity.this,"Failed", Toast.LENGTH_SHORT).show();
}
catch(ClientProtocolException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
它沒有顯示任何的TOAST消息。我沒有得到我應該從中理解的東西。它根本不工作。任何人都可以告訴我,如果代碼有問題..?
吐司在UI線程,通過runOnUiThread您是否收到任何錯誤?如果是,請嘗試發佈這些內容。另外,我開始使用名爲ksoap2的庫來執行我的SOAP請求,我發現它非常方便。 http://code.google.com/p/ksoap2-android/ – hooked82
我沒有收到任何錯誤,但沒有顯示任何TOAST消息。如何在應用程序中使用ksoap2? – Kishan
看看http://www.android10.org/index.php/articleslibraries/167-using-ksoap2-for-android-soap-web-service或谷歌「android ksoap」,你會發現不少文章 – hooked82