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 );
設置連接超時和請求超時,這兩個超時的意義不同,需要分別設置