Skip to main content
 首页 » 编程设计

c#之请求被中止 : Could not create SSL/TLS secure channel. |系统.Net.WebException

2024年02月05日27birdshome

我的 webApi 在其中使用第三方 web api 服务。问题是它在我的本地机器和 Azure Web 服务中完美运行。但是当我将此解决方案传输到 Azure Vm 实例时,出现此错误。我已经安装了与该 3rd 方 web api 相关的正确证书并注册了 HttpClient 并尝试了

ServicePointManager.Expect100Continue = true; 
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11; 

但它给出了同样的错误。我不知道确切的错误是什么。请问有人可以帮忙吗?

请您参考如下方法:

根据我的理解,您可以引用下面的方法来检查这个问题:

1.杠杆https://www.ssllabs.com/ssltest/检查您这边和第三方 Web API 支持的协议(protocol),如下所示:

2.配置SecurityProtocol和ServerCertificateValidationCallback如下:

ServicePointManager.Expect100Continue = true; 
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; 
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls 
            | SecurityProtocolType.Tls11 
            | SecurityProtocolType.Tls12 
            | SecurityProtocolType.Ssl3; 

另外,你可以引用这个类似的issue1和 issue2了解更多详情。