yxhxj2006

常用链接

统计

最新评论

HttpClient 4 和 HttpClient 3 设置超时

HttpClient 4:

连接超时:
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,60000);
// 或者
HttpConnectionParams.setConnectionTimeout(params, 6000);

读取超时:
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,60000);
// 或者
HttpConnectionParams.setSoTimeout(params, 60000);


HttpClient 3:

连接超时:
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(60000);

读取超时:
httpClient.getHttpConnectionManager().getParams().setSoTimeout(60000);

设置get方法请求超时为 5 秒
GetMethod getMethod= new  GetMethod(url);    
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000 ); 

设置连接超时和请求超时,这两个超时的意义不同,需要分别设置

posted on 2013-11-13 20:54 奋斗成就男人 阅读(229) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: