http长连接获取html,cookies改变时获取到的html未发生变化


 public static String sendGetByParam(String url, final List<Header> headerList, final List<NameValuePair> paramList,
        final int reSend) {
        //声明返回结果
        String result = "";
        //开始请求API接口时间
        TimeInterval timer = DateUtil.timer();
        //请求API接口的响应时间
        long endTime = 0L;
        HttpEntity httpEntity = null;
        CloseableHttpResponse httpResponse = null;
        CloseableHttpClient httpClient = null;
        try {
            // 创建连接
            httpClient = HttpClientFactory.getInstance().getHttpClient();
            //创建URIBuilder
            URIBuilder uriBuilder = new URIBuilder(url);
            if (CollUtil.isNotEmpty(paramList)) {
                for (NameValuePair nm : paramList) {
                    //设置参数
                    uriBuilder.setParameter(nm.getName(), nm.getValue());
                }
            }
            url = uriBuilder.build().toString();
            LOG.info("请求URL;{}", url);

            // 设置请求头和报文
            final HttpGet httpGet = HttpClientFactory.getInstance().httpGet(url);
            if (CollUtil.isNotEmpty(headerList)) {
                httpGet.setHeaders(headerList.toArray(new Header[0]));
            }
            httpGet.setHeader("User-Agent",
                "Mozilla/5.0(Windows NT 6.1;Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");
            httpGet.setHeader("cache-control", "no-store, no-cache, must-revalidate");
            //执行发送,获取相应结果
            httpResponse = httpClient.execute(httpGet);
            httpEntity = httpResponse.getEntity();
            result = EntityUtils.toString(httpEntity);
        } catch (final Exception e) {
            LOG.error("请求:{}接口出现异常", url, e);
            if (reSend > 0) {
                LOG.info("请求:{}出现异常:{},进行重发。进行第:{}次重发", url, e.getMessage(), (HttpConstant.REQ_TIMES - reSend + 1));
                result = sendPostByParam(url, headerList, paramList, reSend - 1);
                if (result != null && !"".equals(result)) {
                    return result;
                }
            }
        } finally {
            try {
                EntityUtils.consume(httpEntity);

            } catch (final IOException e) {
                LOG.error("http请求释放资源异常", e);
            }
        }
        LOG.info("spendtime:{},url:{},result:{}", timer.interval(), url, result);
        return result;
    }