找回密码
 新建账号

Powershell The request was aborted: Could not create SSL/TLS secure channel.

[复制链接]
 楼主| 大郎 发表于 2026-7-21 13:58 | 显示全部楼层 |阅读模式
Powershell The request was aborted: Could not create SSL/TLS secure channel. (请求被中止: 未能创建 SSL/TLS 安全通道。)错误最近发生在在 Windows 7 执行 Invoke-RestMethod 时。
  1. PS C:\Users\wuxiancheng\Downloads> wuxiancheng.ps1 -Verbal
  2. Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure channel.
  3. At C:\apps\cmd\wuxiancheng.ps1:113 char:21
  4. +         $Response = Invoke-RestMethod @InvokingArguments
  5. +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  6.     + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
  7.     + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
复制代码
这个问题的产生,是因为 Windows 7 上 .Net 默认不启用高版本 TLS 支持,而现代网站通常只支持高版本 TLS。要解决这个问题,可以改系统注册表,也可以改 Powershell 代码。
方法一、改注册表。需要以管理员身份运行以下 Powershell 代码。
  1. Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value 1 -Type DWORD
  2. Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value 1 -Type DWORD
复制代码
方法二、改 Powershell 代码。在代码前面添加以下代码。
  1. $SecurityProtocolTypes = 0
  2. [Enum]::GetValues([Net.SecurityProtocolType]) | Where-Object {
  3.     $_ -NotIn @([Net.SecurityProtocolType]::Ssl3, [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::SystemDefault)
  4. } | ForEach-Object {
  5.     $SecurityProtocolTypes = $SecurityProtocolTypes -bor $_
  6. }
  7. [Net.ServicePointManager]::SecurityProtocol = $SecurityProtocolTypes
复制代码
允许使用 SSl3、TLS 1.0 以外的所有版本。如果要允许 TLS 1.0,将上述代码中的以下内容去掉即可。
  1. [Net.SecurityProtocolType]::Tls,
复制代码
相关帖子:PowerShell Gallery 已经不支持 TLS 1.0 和 1.1

手机版|轻松e站

GMT+8, 2026-7-21 21:26

快速回复 返回顶部 返回列表