小任班长的博客 - 不同版本超时时间
HttpClient 设置超时时间放在请求阻塞 不同版本超时设置方法
3.X是这样的HttpClient client=new DefaultHttpClient();client.setConnectionTimeout(30000); client.setTimeout(30000);4.X是这样的HttpClient httpClient=new DefaultHttpClient();httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,2000);//连接时间httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间4.3是这样的CloseableHttpClient httpClient = HttpClients.createDefault();HttpGet httpGet=new HttpGet("http://www.baidu.com");//HTTP Get请求(POST雷同)RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(2000).build();//设置请求和传输超时时间httpGet.setConfig(requestConfig);httpClient.execute(httpGet);//执行请求