weixin_43590753 2019-02-18 23:13 采纳率: 0%
浏览 2302
已结题

CloseableHttpClient 4.5.2如何设置等待超时?

CloseableHttpClient 4.5.2中执行response = httpClient.execute(httpPost);
没有任何的等待效果,直接返回无连接,如果我想让他保持请求30秒是否可以?

        RequestConfig defaultRequestConfig  = RequestConfig.custom().
                setConnectTimeout(30000).setConnectionRequestTimeout(30000)
                .setSocketTimeout(30000).build();
        //        CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
        CloseableHttpResponse response = null; 
        String resultString = "";
            HttpPost httpPost = new HttpPost(url);  
            StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);  
            httpPost.setEntity(entity);  

            httpPost.setConfig(defaultRequestConfig);
            String uuid=UuidUtil.getuuid();
            PgmsDao pgms=new PgmsDao();
            LoginUI login=(LoginUI) FacesUtil.getSessionMapValue("loginUI");
            String netid=login.getLdapuser().getNetid();
            String request_user=login.getLdapuser().getName();
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String request_date = sdf.format(new Date());
            Map<String,String> request_map=(Map)new JSONObject().fromObject(json);
            String action=request_map.get("action");

                response = httpClient.execute(httpPost);
                resultString = EntityUtils.toString(response.getEntity(), "utf-8");
                String response_date = sdf.format(new Date());
                Map<String,String>result=(Map)new JSONObject().fromObject(resultString);
                String status=result.get("status");

如果是别的版本也可以,请大佬指点

  • 写回答

3条回答 默认 最新

  • zoyation 2019-02-19 12:41
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错