Apache 的 HttpClient 提供了保持套接字活动的机制。
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).build();
new PoolingHttpClientConnectionManager().setDefaultSocketConfig(socketConfig)
有没有办法使用 Java 17 HttpClient 启用 TCP 保持活动状态?
在您的 http 请求中添加一个 keep-alive 标头怎么样?
例如
HttpRequest request = HttpRequest.newBuilder().uri(URI.create("host"))
.header("Connection", "keep-alive")
.POST(json.body)).build()