解决无法建立SSL / TLS安全通道(The request was aborted: Could not create SSL/TLS secure channel)的问题

解决无法建立SSL / TLS安全通道(The request was aborted: Could not create SSL/TLS secure channel)的问题

这个问题主要是没配置好SSL版本

在谷歌浏览器中打开该链接,按下F12,打开开发者工具,切换到Security选项卡,就可以看到了。这一串说明:
The connection to this site is encrypted and authenticated using TLS 1.2, ECDHE_RSA with P-256, and AES_128_GCM.
就是 TLS1.2
各SSL版本与C#代码的对应:

SSL/TLS版本对应C#代码
SSL 3ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
TLS 1.0ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
TLS 1.1ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
TLS 1.2ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

在发起https请求前使用以下代码

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
//如果编译器报错:未包含"Tls11"的定义,用以下代码,要解决这个报错也可以安装.net framework 4.5
//System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | (SecurityProtocolType)3072 | (SecurityProtocolType)768 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{   // 总是接受  
    return true;
});//验证服务器证书回调自动验证

原文链接:http://blog.albsz.cn/2020-11-05-sslTlsFail.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值