/**
*
* @Description https post请求,参数为字符串
* @param param
* @param url
* @param socketTimeout 毫秒数量
* @return String
* @throws Exception
* @author X Yang
* @date 2017年6月28日 下午1:28:30
*/
CloseableHttpClient httpclient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
String responseData = null;
try {
HttpPost request = new HttpPost(url);
// 解决中文乱码问题
StringEntity entity = new StringEntity(requestData, "utf-8");
entity.setContentType("application/json");
request.setEntity(entity);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(360000).setConnectTimeout(600000).build();
// 设置请求和传输超时时间
request.setConfig(requestConfig);
CloseableHttpResponse response = httpclient.execute(request);
url = URLDecoder.decode(url, "UTF-8");
log.info("请求接口:" + url + ",执行状态:" + response.getStatusLine().getStatusCode());
/** 请求发送成功,并得到响应 **/
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
try {
/** 读取服务器返回过来的字符串数据 **/
responseData = EntityUtils.toString(response.getEntity(), "UTF-8");
} catch (Exception e) {
log.error("post请求提交失败:" + url, e);
} finally {
response.close();
}
} else {
responseData = response.getStatusLine().getStatusCode() + "-" + response.getStatusLine().getReasonPhrase();
}
} catch (Exception e) {
log.error("post请求提交失败:" + url, e);
} finally {
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Timestamp responseTime = new Timestamp(System.currentTimeMillis());
log.debug("第三方接口-响应时间:" + sdf.format(responseTime));
log.debug("第三方接口-响应报文:" + responseData);
return responseData;
}