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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名