让 Winhttp 支持 TLS1.1/TLS1.2 ,网页访问返回空白的解决方法

2021年10月19日 技术资料 2595 views 0

WINHTTP_OPTION_SECURE_PROTOCOLS
Sets an unsigned long integer value that specifies which secure protocols are acceptable. By default only SSL3 and TLS1 are enabled in Windows 7 and Windows 8. By default only SSL3, TLS1.0, TLS1.1, and TLS1.2 are enabled in Windows 8.1 and Windows 10. The value can be a combination of one or more of the following values.

所以对于 Winhttp 来说,官方给的解释是, TLS1.2 只有在 Win8.1 和 Win 10 上才默认支持

下面贴代码:
WinHttpSetOption (hSession, #WINHTTP_OPTION_SECURE_PROTOCOLS, 位或 (#WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2, #WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1, #WINHTTP_FLAG_SECURE_PROTOCOL_SSL2, #WINHTTP_FLAG_SECURE_PROTOCOL_SSL3, #WINHTTP_FLAG_SECURE_PROTOCOL_TLS1), 4)


win 10 其实默认就支持,并不需要执行上面的代码,上面的代码有什么用呢?答曰没多大用,只是说明原理。

那么 win7 用户应该怎么办?就需要安装这个更新:
更新下载:http://www.catalog.update.microsoft.com/search.aspx?q=kb3140245


下载自己的版本对应的,安装之后重启,然后要设置注册表

以 win7x64 为例:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp]
"DefaultSecureProtocols"=dword:00000a00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\WinHttp]
"DefaultSecureProtocols"=dword:00000a00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings]
"SecureProtocols"=dword:00000a80
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]
"SecureProtocols"=dword:00000a80



如果自己添加不来,微软也提供了工具,运行完成后重启即可。此时在 win7x64 测试,发现刚才 send 失败的苹果页面已经可以访问成功。

👍好活当赏🧧