zoukankan      html  css  js  c++  java
  • httpClient连接超时设置

    注: 每个HttpClinet对象设置都不一样

    这里已3.x和4.x为例说明

    1)3.X版本

    创建连接

    HttpClient httpClient=new DefaultHttpClient();

    这是个3.X的超时设置方法

    HttpClient client = new HttpClient();

    client.setConnectionTimeout(30000);

    client.setTimeout(30000);

    HttpClient httpClient= new HttpClient();

    httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);

    2)4.3版本

    创建连接

    CloseableHttpClient httpClient = HttpClients.createDefault();

    4.X版本的超时设置(4.3后已过时)

    HttpClient httpClient=new DefaultHttpClient();

    httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,2000);//连接时间

    httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,2000);//数据传输时间

    4.3版本超时设置

    CloseableHttpClient httpClient = HttpClients.createDefault();

    HttpGet httpGet=new HttpGet("http://www.baidu.com");//HTTP Get请求(POST雷同)

    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(2000).build();//设置请求和传输超时时间

    httpGet.setConfig(requestConfig); httpClient.execute(httpGet);//执行请求

    我不生产知识 我只是知识的搬运工
  • 相关阅读:
    HDU 2013(递归)
    紫书搜索 习题7-6 UVA
    紫书搜索 习题7-4 UVA
    紫书搜索 习题7-3 UVA
    紫书搜索 习题7-2 UVA
    紫书搜索 习题7-1 UVA
    紫书搜索 例题7-10 UVA
    紫书搜索 例题7-13 UVA
    紫书搜索 例题7-12 UVA
    紫书搜索 例题7-9 UVA
  • 原文地址:https://www.cnblogs.com/yyy-blog/p/5623593.html
Copyright © 2011-2022 走看看