sending SOAP request
In my application I want to send a SOAP request to some url, the SOAP request to be sent is as below
POST /TelLink/Wrench开发者_高级运维ENTService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WrenchGlobal/GetToDoList"
<?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>
<GetToDoList xmlns="http://WrenchGlobal/">
<viPeriod>int</viPeriod>
<vsUserID>string</vsUserID>
</GetToDoList>
</soap:Body>
</soap:Envelope>
In the above code, I will have to replace "int" and "string" with actual values and it will invoke GetToDoList on the server. My problem is, I dont know how to send this request to the server? (using httppost) Could anyone help me out?
int viPeriod;
String vsUserID;
String NAMESPACE = "http://WrenchGlobal/";
String SOAP_ACTION = "http://WrenchGlobal/GetToDoList";
String METHOD_NAME = "GetToDoList";
String result = null;
Object resultRequestSOAP = null;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("viPeriod", viPeriod);
request.addProperty("vsUserID", vsUserID);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
String requestDumpString = androidHttpTransport.requestDump;
System.out.println("requestDump : " + requestDumpString);
resultRequestSOAP = envelope.getResponse(); // Output received
result = resultRequestSOAP.toString(); // Result string
System.out.println("OUTPUT : " + result);
} catch (Exception e) {
e.printStackTrace();
}
Hope this would help.
IntentService HttpPost are probably what you want. There are plenty of snippets available on Google; here's just one of them.
精彩评论