HttpClient中的超时设置和请求重试

1,设置get方法请求超时为 5 秒

Java代码
  1. GetMethod getMethod=new GetMethod(url);     
  2. getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000);  
GetMethod getMethod=new GetMethod(url);  
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000);

 

 

2,设置 Http 连接超时为5秒

Java代码
  1. HttpClient httpClient=new HttpClient();   
  2.  httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);  
 HttpClient httpClient=new HttpClient();
  httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

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

来源:http://xuganggogo.iteye.com/blog/366562

你可能感兴趣的:(HttpClient)