当我尝试使用时Invoke-WebRequest
我收到一些奇怪的错误:
Invoke-WebRequest -Uri "https://idp.safenames.com/"
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
我不确定是什么原因造成的,因为网站本身看起来很好。
即使使用了 stackoverflow 上的所有“忽略 ssl 错误”功能,它仍然无法工作,这让我想知道它是否与 SSL 有关。
As 培根比特笔记 https://stackoverflow.com/a/36266139/712649,.NET 版本 > 4.5 默认使用 SSLv3 和 TLS 1.0。
您可以通过设置来更改此行为SecurityProtocol https://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.securityprotocol(v=vs.110).aspx政策与ServicePointManager
class:
PS C:\> $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
PS C:\> [System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
PS C:\> (Invoke-WebRequest -Uri "https://idp.safenames.com/").StatusCode
200
这将适用于 AppDomain 中的所有请求(因此它仅适用于主机应用程序的当前实例)。
There's GitHub 上的模块 https://github.com/markekraus/BetterTls现在可以在 PSGallery 中管理这些设置:
Install-Module BetterTls -Scope CurrentUser
Import-Module BetterTls
Enable-Tls -Tls11 -Tls12
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)