HttpClient 设置超时时间

概要:

HttpClient 设置超时时间

| |目录

HttpClient 4.3.x:

RequestConfig requestConfig = RequestConfig.custom()
        .setSocketTimeout(1000)
        .setConnectTimeout(1000)
        .build();
HttpGet httpget1 = new HttpGet("http://localhost/1");
httpget1.setConfig(requestConfig);

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);


评论关闭
评论 还能输入200
评论关闭
评论 还能输入200
  • 全部评论(0)
资料加载中...
已关注 , 取消