Last Updated: November 21, 2017
·
13.68K
· terukizm

SOAP request by org.apache.http.client.HttpClient(4.1)

// SOAP request(xml) read-in
 File req_xml = new File("test/xml/request.xml");

 // SOAP request send
 HttpPost post = new HttpPost("http://localhost:8080/test/api/");
 post.setEntity(new InputStreamEntity(new FileInputStream(req_xml), req_xml.length()));
 post.setHeader("Content-type", "text/xml; charset=UTF-8");
 post.setHeader("SOAPAction", "");
 HttpClient client = new DefaultHttpClient();
 HttpResponse response = client.execute(post);

 // SOAP response(xml) get
 String res_xml = EntityUtils.toString(response.getEntity());