HttpClient设置超时
2014-06-19 11:16
330 查看
有时使用httpclient的时候,需要等待N长时间,可能此时你决定放弃或者重试。实现上非常简单添加一个参数即可
1,设置get方法请求超时为 5 秒
2,设置 Http 连接超时为5秒
设置连接超时和请求超时,这两个超时的意义不同,需要分别设置。
//这里的超时单位是毫秒。这里的http.socket.timeout相当于SO_TIMEOUT httpClient.getParams().setIntParameter("http.socket.timeout",3000);
HttpConnectionManagerParams managerParams = httpClient.getHttpConnectionManager().getParams(); // 设置连接超时时间(单位毫秒) managerParams.setConnectionTimeout(30000); // 设置读数据超时时间(单位毫秒) managerParams.setSoTimeout(120000);
1,设置get方法请求超时为 5 秒
GetMethod getMethod= new GetMethod(url); getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000 );
2,设置 Http 连接超时为5秒
HttpClient httpClient= new HttpClient(); httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000 );
设置连接超时和请求超时,这两个超时的意义不同,需要分别设置。
相关文章推荐
- HttpClient 4 和 HttpClient 3 设置超时
- httpclient-4.X设置连接超时
- android - DefaultHttpClient设置超时.
- HttpClient超时设置
- httpclient 超时设置
- HttpClient设置超时的问题
- HttpClient 设置超时
- android httpclient 设置超时
- HttpClient设置代理,超时,以及得到cookies
- httpclient 超时设置
- 设置DefaultHttpClient和HttpClient的超时时间的方法
- httpclient 超时设置
- apache httpclient4 设置超时时间
- HttpClient连接请求超时设置
- HttpClient设置超时和代理
- httpclient4 请一定设置超时时间
- httpclient 超时设置
- HttpClient超时设置_demo
- httpclient超时设置
- 设置Apache的HttpClient请求时间超时