public static String send(String url, String encryptMsg) throws Exception { HttpClientBuilder httpClientBuilder = HttpClients.custom(); CloseableHttpClient httpClient = httpClientBuilder.setSSLContext(sslContext) .setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); HttpPost httpPost = new HttpPost(url); RequestConfig requestConfig = RequestConfig.custom() .setSocketTimeout(10000) .setConnectTimeout(10000) .build(); httpPost.setConfig(requestConfig); StringEntity entityParam = new StringEntity(encryptMsg); entityParam.setContentType(CONTENT_TYPE); httpPost.setEntity(entityParam); httpPost.setHeader(SERIAL_NUM, String.valueOf(RandomUtils.nextInt())); CloseableHttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); byte[] resultBytes = EntityUtils.toByteArray(entity); return new String(resultBytes); }
回答
你设置的这两个超时是TCP连接握手超时,还需设置connectionRequestTimeout
我看这个时间是指从连接池获取连接的timeout 我没有用到连接池 就没有设置这个时间 而且我的项目在测试环境的请求频率很低很低 按理说也绝对不可能7s中没有拿到链接从而报链接超时
有2个超时
1. 链接超时,就是三次握手时间超时
2. 相应超时,处理数据+返回数据+接收数据时间
PS: 去源码中搜下Timeout,应该还有一个
发表评论