/**
* 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;
* 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微信公众平台开发之生成带参二维码 可以去参考