public static String requestByPostMethod(String url, List paramList) {
CloseableHttpClient httpClient = getHttpClient();
try {
HttpPost post = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000).build();//设置请求和传输超时时间
post.setConfig(requestConfig);
UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(paramList, "UTF-8");
post.setEntity(uefEntity);
System.out.println("POST 请求...." + post.getURI());
CloseableHttpResponse httpResponse = httpClient.execute(post);
try {
HttpEntity entity = httpResponse.getEntity();
if (null != entity) {
String result = EntityUtils.toString(entity, "UTF-8");
return result;
}
} finally {
httpResponse.close();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
closeHttpClient(httpClient);
} catch (Exception e) {
e.printStackTrace();
}
}
return "";
}
有一台机器没部署 恰好打到上面了 汗~