feat:httpClient 配置

This commit is contained in:
Zhujx
2025-07-28 17:25:20 +08:00
parent 81eda3ae6e
commit 2a4f4da781
2 changed files with 9 additions and 7 deletions

View File

@@ -31,9 +31,9 @@ public class HttpClientConfig {
// 建立连接的超时时间 // 建立连接的超时时间
.setConnectTimeout(5000) .setConnectTimeout(5000)
// 响应超时时间 // 响应超时时间
.setSocketTimeout(10000) .setSocketTimeout(5000)
// 从连接池获取连接的超时时间 // 从连接池获取连接的超时时间
.setConnectionRequestTimeout(1000) .setConnectionRequestTimeout(5000)
.build(); .build();
// 创建 HttpClient // 创建 HttpClient

View File

@@ -25,11 +25,11 @@ import java.util.concurrent.TimeUnit;
@Slf4j @Slf4j
public class HttpUtils { public class HttpUtils {
private static final int socketTimeOut = 60 * 1000; private static final int socketTimeOut = 5000;
private static final int connectTimeout = 60 * 1000; private static final int connectTimeout = 5000;
private static final int connectionRequestTimeout = 15 * 1000; private static final int connectionRequestTimeout = 5000;
private static final int defaultMaxPerRoute = 500; private static final int defaultMaxPerRoute = 20;
private static final int maxTotal = 2000; private static final int maxTotal = 100;
private static final RequestConfig requestConfig = RequestConfig.custom() private static final RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout) .setConnectTimeout(connectTimeout)
@@ -133,6 +133,7 @@ public class HttpUtils {
private static HttpPost getPost(String url, Map<String, String> header, String jsonParams) { private static HttpPost getPost(String url, Map<String, String> header, String jsonParams) {
HttpPost httpPost = new HttpPost(url); HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json"); httpPost.addHeader("Content-Type", "application/json");
httpPost.setHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.61(0x18003d2e) NetType/WIFI Language/zh_CN");
// 创建请求内容 // 创建请求内容
StringEntity entity = new StringEntity(jsonParams, "utf-8"); StringEntity entity = new StringEntity(jsonParams, "utf-8");
entity.setContentType("application/json"); entity.setContentType("application/json");
@@ -170,6 +171,7 @@ public class HttpUtils {
HttpGet httpGet = new HttpGet(url + request); HttpGet httpGet = new HttpGet(url + request);
httpGet.addHeader("Content-Type", "application/json"); httpGet.addHeader("Content-Type", "application/json");
httpGet.setHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.61(0x18003d2e) NetType/WIFI Language/zh_CN");
if (MapUtils.isNotEmpty(header)) { if (MapUtils.isNotEmpty(header)) {
for (Map.Entry<String, String> entry : header.entrySet()) { for (Map.Entry<String, String> entry : header.entrySet()) {
httpGet.setHeader(entry.getKey(), entry.getValue()); httpGet.setHeader(entry.getKey(), entry.getValue());