【问题标题】:Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channelInvoke-WebRequest:请求被中止:无法创建 SSL/TLS 安全通道
【发布时间】:2019-06-17 06:01:24
【问题描述】:
Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel.
At line:4 char:6
+ $r = Invoke-WebRequest -Uri $url
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

当其他应用程序试图访问我的服务时,我的客户遇到了这个问题。 我启用了 TLS 1.1。和 1.2 在我的服务器上

【问题讨论】:

  • 其他方调用我们的服务,他们遇到了这个问题...
  • 你能贴出调用网络服务的代码吗?您能否发布有关如何启用 TLS 1.1 和 1.2 的详细信息
  • 这是第三方代码,所以我们没有该代码。
  • 在浏览器-->高级设置中我启用了 TLS 1.1。和 1.2

标签: asp.net-mvc


【解决方案1】:

如果客户端尝试使用 TLS 1.0 协商请求,但仅支持 TLS 1.1 和 1.2,您将收到此错误。

在向您的服务发出请求之前,尝试通过将以下代码添加到客户端的应用程序来强制客户端使用 TLS 1.2。

PowerShell:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

C#:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

见:

Update .NET web service to use TLS 1.2

Powershell Setting Security Protocol to Tls 1.2

【讨论】:

  • 感谢您的回复。
  • 0 你的意思是说我应该要求第三方在调用我们的服务之前将以下代码添加到他们的应用程序中??? System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;这意味着问题出在他们的网站上??因为我已经在我们的服务器上启用了所有的 TLS 版本。
  • @priyankagharat 您能否确认您发布的错误消息来自客户的应用程序?您确定客户端尝试调用的 URL 支持 TLS 1.0 吗? .NET 4.5 及更早版本将默认使用 TLS 1.0,并且您在问题中声明仅启用了 1.1 和 1.2。如果是这种情况,您将收到您发布的错误消息。
  • 外部应用程序试图关闭我们的服务。作为响应,他们得到了这个 iisue。
  • 我们使用的是 .net 4.6
【解决方案2】:

错误原因是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"

【讨论】:

    【解决方案3】:

    你的意思是说我应该要求第三方在调用我们的服务之前将以下代码添加到他们的应用程序中???

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

    这意味着问题出在他们的网站上?? 因为我已经在我们的服务器上启用了所有的 TLS 版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-15
      • 2012-06-05
      • 2018-04-22
      • 2012-10-30
      相关资源
      最近更新 更多