0
我试着用httpPost访问肥皂Ws的,这是我的代码如何访问SOAP Web服务的Android
HttpPost httpPost=new HttpPost(WebService Url);
httpPost.addHeader("Content-Type", "application/soap+xml; charset=utf-8");
httpPost.addHeader("Host", HostName);
//get from the getflashinfo method;
String soapRequestXml=getFlashInfo(0);
Log.d("Message12", soapRequestXml);
try
{
StringEntity se=new StringEntity(soapRequestXml, HTTP.UTF_8);
se.setContentType("text/xml");
httpPost.setEntity(se);
HttpClient hC=new DefaultHttpClient();
HttpResponse reponse=hC.execute(httpPost);
Log.d("Message12", response.toString());
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
二功能
String getFlashInfo(int target)
{
String sHeaderRequest="<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">"+
"<s:Header>" +
"<a:Action s:mustUnderstand=\"1\">http://tempuri.org/IFlashInfoService/GetFlashInfo</a:Action>" +
"<a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo>" +
"<a:To s:mustUnderstand=\"1\">URL</a:To>" +
"</s:Header>" +
"<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
"<GetIdTargetRequest xmlns=\"http://tempuri.org/\">" ;
String sHeaderRequest1;
if (target > 0)
{
sHeaderRequest1="<IdTarget>"+" "+target+" "
+"</IdTarget>";
}
else
{
sHeaderRequest1="<IdTarget>0</IdTarget>";
}
sHeaderRequest=sHeaderRequest+sHeaderRequest1;
sHeaderRequest=sHeaderRequest+"</GetIdTargetRequest>";
sHeaderRequest=sHeaderRequest+"</s:Body>";
sHeaderRequest=sHeaderRequest+"</s:Envelope>";
Log.d("Message12", sHeaderRequest);
return sHeaderRequest;
}
我得到空指针异常时尝试登录的效应初探消息
我用Ksop库
got some kind of xmlparse error and unknown source exception
请帮我
问候, Kariyachan
看看android库http://code.google.com/p/ksoap2-android/ – ernazm 2011-05-26 10:47:19
的SOAP库感谢我用于该库的回复。但最终会出错。 – DroidBot 2011-05-26 10:57:38