Java 17 HttpClient-套接字保持活动

问题描述 投票:0回答:1

Apache 的 HttpClient 提供了保持套接字活动的机制。

 SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).build();
 new PoolingHttpClientConnectionManager().setDefaultSocketConfig(socketConfig)

有没有办法使用 Java 17 HttpClient 启用 TCP 保持活动状态?

java java-17 java-http-client
1个回答
0
投票

在您的 http 请求中添加一个 keep-alive 标头怎么样?

例如

HttpRequest request = HttpRequest.newBuilder().uri(URI.create("host"))
.header("Connection", "keep-alive")
.POST(json.body)).build()
© www.soinside.com 2019 - 2024. All rights reserved.