apache httpclient4 设置超时时间

apache httpclient4 设置超时时间

旧的方法(已被禁用)

CloseableHttpClient httpclient = HttpClients.createDefault();
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,5000);
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,5000);

新的方法

HttpPost httppost = new HttpPost(httpUrl);
//设置超时时间为5秒
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(5000).setConnectTimeout(5000).setSocketTimeout(5000).build();
httppost.setConfig(requestConfig);


你可能感兴趣的:(apache,httpclient4,设置超时时间)