Android, sending XML via HTTP POST (SOAP)

  1. First, you can create a String template for this SOAP request and substitute user-supplied values at runtime in this template to create a valid request.
  2. Wrap this string in a StringEntity and set its content type as text/xml
  3. Set this entity in the SOAP request.

Something like:

HttpPost httppost = new HttpPost(SERVICE_EPR);          
StringEntity se = new StringEntity(SOAPRequestXML,HTTP.UTF_8);

se.setContentType("text/xml");  
httppost.setHeader("Content-Type","application/soap+xml;charset=UTF-8");
httppost.setEntity(se);  

HttpClient httpclient = new DefaultHttpClient();
BasicHttpResponse httpResponse = 
    (BasicHttpResponse) httpclient.execute(httppost);

response.put("HTTPStatus",httpResponse.getStatusLine().toString());

Leave a Comment