/**
* post请求 ,请求数据放到body里
* @param url 请求地址
* @param bodyData 参数
* @author wangyj
* @date 2019年4月20日
*/
public static String doPostBodyData(String url, String bodyData) throws Exception{
String result = "";
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
try {
HttpPost httpPost = getHttpPost(url, null); // 请求地址
httpPost.setEntity(new StringEntity(bodyData, Encoding));
httpClient = getHttpClient();
// 得到返回的response
response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
result = getResult(entity, Encoding);
} catch (Exception e) {
throw e;
} finally {
// 关闭httpClient
if (null != httpClient) {
httpClient.close();
}
// 关闭response
if (null != response) {
EntityUtils.consume(response.getEntity()); // 会自动释放连接
response.close();
}
}
return result;
}