13
Jul
Request.setEntity() to attach an XML load to a REST request via HttpClient
Following code demonstrates how to attach a XML Load while sending request to server for processing
// Payload for XML Request
String xmlLoad = “
HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(“http://endpoint location”);
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, “application/xml”);
StringEntity xmlEntity = new StringEntity(xmlLoad);
httpPost.setEntity(xmlEntity);
HttpResponse response = httpClient.execute(httpPost);
assertEquals(response.getStatusLine().getStatusCode(), 200);
0 comments