HttpClient 4:
連接超時(shí):
httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,60000);
// 或者
HttpConnectionParams.setConnectionTimeout(params, 6000);
讀取超時(shí):
httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,60000);
// 或者
HttpConnectionParams.setSoTimeout(params, 60000);
HttpClient 3:
連接超時(shí):
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(60000);
讀取超時(shí):
httpClient.getHttpConnectionManager().getParams().setSoTimeout(60000);
設(shè)置get方法請(qǐng)求超時(shí)為 5 秒
GetMethod getMethod= new GetMethod(url);
getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,5000 );
設(shè)置連接超時(shí)和請(qǐng)求超時(shí),這兩個(gè)超時(shí)的意義不同,需要分別設(shè)置