HttpClient 发送XML请求



@Test
public void test_payNotify(){

String reqXML="<xml></xml>";


CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
try {

InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(reqXML.getBytes()));
reqEntity.setContentType("application/xml");
reqEntity.setContentEncoding("utf-8");
reqEntity.setChunked(true);

HttpUriRequest request = RequestBuilder.post()
.setUri(new URI(path + "/receive/WECHAT"))
.setEntity(reqEntity)
.build();

response = httpclient.execute(request);

HttpEntity entity = response.getEntity();

System.out.println("response statusLine: " + response.getStatusLine());

String jsonstr = EntityUtils.toString(entity);

logger.info("response:"+jsonstr);
response.close();
httpclient.close();

} catch (Exception e) {
e.printStackTrace();
}


}


发布了201 篇原创文章 · 获赞 5 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/mutourenoo/article/details/84923203