我正在尝试执行这个powershell命令
Invoke-WebRequest -Uri https://apod.nasa.gov/apod/
我得到了这个错误。"Invoke-WebRequest :请求被中止:无法创建SSL/TLS安全通道“https请求似乎正常工作("https://google.com"),但这个没有问题。如何使其工作或使用其他powershell命令读取页面内容?
发布于 2017-01-12 17:03:45
试着用这个
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri https://apod.nasa.gov/apod/
发布于 2017-12-30 03:00:20
在一个无耻的企图窃取一些选票,SecurityProtocol
是一个具有[Flags]
属性的Enum
。所以你可以这么做:
[Net.ServicePointManager]::SecurityProtocol =
[Net.SecurityProtocolType]::Tls12 -bor `
[Net.SecurityProtocolType]::Tls11 -bor `
[Net.SecurityProtocolType]::Tls
或者因为这是PowerShell,所以可以让它为您解析一个字符串:
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
那么技术上你就不需要知道TLS版本了。
我从我阅读了这个答案后创建的脚本中复制并粘贴了它,因为我不想循环所有可用的协议来找到一个工作的协议。当然,如果你愿意的话,你可以这么做。
最后注意--我的PowerShell配置文件中有原始的(减去编辑的)语句,所以它在我现在开始的每个会话中都有。这并不是完全万无一失的,因为仍然有一些网站只是失败,但我肯定看到的信息被质疑的次数少了很多。
发布于 2021-03-13 13:27:02
错误的原因是Powershell默认使用TLS 1.0连接到网站,但是网站安全需要TLS 1.2。可以通过运行以下任何命令来更改此行为以使用所有协议。您还可以指定单个协议。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12, [Net.SecurityProtocolType]::Ssl3
[Net.ServicePointManager]::SecurityProtocol = "Tls, Tls11, Tls12, Ssl3"
运行这些命令之后,尝试运行您的命令:
Invoke-WebRequest -Uri https://apod.nasa.gov/apod/
那就成功了。
https://stackoverflow.com/questions/41618766
复制相似问题