DefaultHttpClient httpClient = null;
String bankReturnStr = null;
try {
// 生成httpClient
httpClient = HttpClientUtil.generateWrapHttpClient("TLSv1.2");
httpClient.setHttpRequestRetryHandler(new GBHttpRequestRetryHandler());
HttpPost httpPost = new HttpPost(url);
//设置超时时间
/*RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(1).setConnectionRequestTimeout(1)
.setSocketTimeout(1).build();
httpPost.setConfig(requestConfig);*/
httpPost.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
httpPost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000);
StringEntity entityParams = new StringEntity(this.parseXML(map),"utf-8");
httpPost.setEntity(entityParams);
httpPost.setHeader("Content-Type", "text/xml;charset=ISO-8859-1");
((AbstractHttpClient) httpClient).setHttpRequestRetryHandler(new GBHttpRequestRetryHandler(1,true));
//response = httpClient.execute(httpPost);
Map<String, String> sendResult = HttpClientUtil.postRequest(httpClient, httpPost, null, "UTF-8", false);
// 解析结果
bankReturnStr = HttpClientUtil.getResponseInfo(sendResult);
} catch (Exception e) {
throw e;
} finally {
httpClient.getConnectionManager().shutdown();
}
这种方式设置失效,版本4.5.
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(1).setConnectionRequestTimeout(1)
.setSocketTimeout(1).build();
httpPost.setConfig(requestConfig);
后续修改为过期方法却可以为
httpPost.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
httpPost.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, 30000);