首页  

httpclient 超时设置     所属分类 java 浏览量 209
httpclient
4.3版本之前
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,7000);
httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,9000);

4.3版本之后
RequestConfig requestConfig =  RequestConfig.custom().setSocketTimeout(7000).setConnectTimeout(9000).build();
httpGet.setConfig(requestConfig);
httpPost.setConfig(requestConfig);

jdk HttpURLConnection
URLConnection conn = urlo.openConnection();
HttpURLConnection huc = (HttpURLConnection) conn;
conn.setConnectTimeout(connectTimeout);
conn.setReadTimeout(readTimeout);


https://gitee.com/dyyx/hellocode/blob/master/project/jpress/src/main/java/dyyx/util/HttpClientUtil.java https://gitee.com/dyyx/hellocode/blob/master/project/jpress/src/main/java/dyyx/util/SimpleHttpClientUtil.java 超时测试代码 https://gitee.com/dyyx/hellocode/blob/master/project/jpress/src/test/java/dyyx/util/HttpClientUtilTimeoutTest.java https://gitee.com/dyyx/hellocode/blob/master/project/jpress/src/test/java/dyyx/util/SimpleHttpClientUtilTimeoutTest.java

上一篇     下一篇
GO入门指南实例

temporal压测方案及记录

prometheus metrics 格式说明

Borg Omega and Kubernetes

k8s架构及核心组件

k8s概述