httpclient超时配置

httpClient 各个版本超时配置

com.apache下的包,设置超时问题:
3.x版本 :
HttpClient client = new HttpClient();  
client.setConnectionTimeout(30000);   
client.setTimeout(30000);  
HttpClient httpClient= new HttpClient();   
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);  
4.3之前版本
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");  
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000)
.setConnectionRequestTimeout(1000).setSocketTimeout(5000).build();  
httpGet.setConfig(requestConfig);  
httpClient.execute(httpGet);

你可能感兴趣的:(问题记录,apache,java)