hew*_*one 219 powershell ssl
我正在尝试执行此powershell命令
Invoke-WebRequest -Uri https://apod.nasa.gov/apod/
我收到这个错误."Invoke-WebRequest:请求已中止:无法创建SSL/TLS安全通道." https请求似乎有效(" https://google.com ")但不是这个问题.如何让它工作或使用其他powershell命令来读取页面内容?
Cha*_*Rai 447
尝试使用这个
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri https://apod.nasa.gov/apod/
Run Code Online (Sandbox Code Playgroud)
No *_*rns 147
在一个无耻企图窃取一些票,SecurityProtocol是一个Enum与[Flags]属性.所以你可以这样做:
[Net.ServicePointManager]::SecurityProtocol =
[Net.SecurityProtocolType]::Tls12 -bor `
[Net.SecurityProtocolType]::Tls11 -bor `
[Net.SecurityProtocolType]::Tls
Run Code Online (Sandbox Code Playgroud)
或者因为这是PowerShell,你可以让它为你解析一个字符串:
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Run Code Online (Sandbox Code Playgroud)
那你从技术上讲不需要知道TLS版本.
我在阅读这个答案之后从我创建的脚本中复制并粘贴了这个,因为我不想遍历所有可用的协议来找到一个有效的协议.当然,如果你愿意,你可以这样做.
最后的注意事项 - 我的PowerShell配置文件中有原始(减去SO编辑)语句,所以它在我现在开始的每个会话中.它并非完全万无一失,因为仍有一些网站失败但我肯定会更频繁地看到有问题的信息.
Sid*_*qui 30
错误原因是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"
Run Code Online (Sandbox Code Playgroud)
运行这些命令后,尝试运行您的命令:
Invoke-WebRequest -Uri https://apod.nasa.gov/apod/
Run Code Online (Sandbox Code Playgroud)
然后它就会起作用。
小智 11
这个为我工作
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Run Code Online (Sandbox Code Playgroud)
如果像我一样,上述方法都不奏效,那么单独尝试较低的 TLS 版本可能也值得。我已经尝试了以下两种方法,但似乎没有解决我的问题:
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls
Run Code Online (Sandbox Code Playgroud)
最后,只有当我以 TLS 1.0 为目标(特别是删除代码中的 1.1 和 1.2)时,它才起作用:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls
Run Code Online (Sandbox Code Playgroud)
本地服务器(正在尝试使用)与 TLS 1.2 兼容,尽管远程服务器(先前由第 3 方“确认”为 TLS 1.2 良好)似乎不是。
希望这可以帮助某人。
| 归档时间: |
|
| 查看次数: |
113110 次 |
| 最近记录: |