服务器根据URL以及data信息与微信服务器交互的post请求方法(之一)

来源:互联网 发布:淘宝购物怎样返利 编辑:程序博客网 时间:2024/06/08 04:12
/**
* POST请求
*
* @param url
* URL
* @param xml
* XML
* @return 返回结果
*/
public static String post(String url, String xml) {
Assert.hasText(url);

String result = null;
try {
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new StringEntity(xml, "UTF-8"));
CloseableHttpResponse httpResponse = HTTP_CLIENT.execute(httpPost);
try {
HttpEntity httpEntity = httpResponse.getEntity();
if (httpEntity != null) {
result = EntityUtils.toString(httpEntity, "UTF-8");
EntityUtils.consume(httpEntity);
}
} finally {
try {
httpResponse.close();
} catch (IOException e) {
}
}
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (ClientProtocolException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (ParseException e) {
throw new RuntimeException(e.getMessage(), e);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
return result;

}


某作者的Java微信公众平台开发之生成带参二维码 可以去参考


阅读全文
0 0
原创粉丝点击