在 RequestConfig 和 SocketConfig 中设置套接字超时对于 HTTP 和 HTTPS 的工作方式不同 [英] setting socket timeout in both RequestConfig and SocketConfig works differently for HTTP and HTTPS

查看:100
本文介绍了在 RequestConfig 和 SocketConfig 中设置套接字超时对于 HTTP 和 HTTPS 的工作方式不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SocketConfig 中设置了套接字超时,并将 SocketConfig 设置为连接管理器

I have set socket timeout in SocketConfig and set SocketConfig to connection manager as

connManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(soTimeout).build())

并通过在RequestConfig中将其设置为

httpRequest.setConfig(RequestConfig.copy(defaultRequestConfig).setSocketTimeout(timeout).build())  

参考链接.

对于所有 http 请求,使用 RequestConfig 设置的新值会按预期覆盖旧值.但是对于 https 请求,它总是考虑在 SocketConfig 中设置的旧值.

For all http requests, the new value set using RequestConfig is overwriting the old value as expected. But for https requests it is always considering the old value which was set in SocketConfig.

在了解到这可能是 4.3.1 参考中的问题后,我还将 httpclient 从 4.3.1 升级到 4.3.6 链接.但即使这样也无助于我解决问题.
我错过了什么吗?关于如何解决这个问题的任何想法?

I also upgraded httpclient from 4.3.1 to 4.3.6 after learning that this could be an issue in 4.3.1 reference link. But even this didn't help me solving the issue.
Am I missing anything ? Any idea on how I can solve this issue ?

推荐答案

这只是部分正确.RequestConfig 代表请求级设置,而SocketConfig代表连接级设置.安全连接需要先进行 SSL/TLS 握手并建立安全会话,然后才能使用它们执行请求.因此,RequestConfig 设置只能在 HTTPS 连接完全建立后才能使用.在此之前,只有 SocketConfig 适用.

This is only partially true. RequestConfig represents request level settings, while SocketConfig represents connection level settings. Secure connections need to do a SSL/TLS handshake and establish a secure session before they can be used to execute requests. Therefore, RequestConfig settings can be allied only after HTTPS connection has been fully established. Until then only SocketConfig apply.

这篇关于在 RequestConfig 和 SocketConfig 中设置套接字超时对于 HTTP 和 HTTPS 的工作方式不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆