我正在使用以下代码发送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消息。我没有得到我应该从中理解的东西。它根本不起作用。谁能告诉我代码是否有问题......?
答案 0 :(得分:0)
通过runOnUiThread显示ui线程中的Toast,例如
runOnUiThread(new Runnable() {
public void run() {
Toast.makeText(TelLinkActivity.this,"Failed", Toast.LENGTH_SHORT).show();
}
});