标签:
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);
标签:
原文地址:http://my.oschina.net/u/914897/blog/411130