切换TLS1.2后,C#请求报错:请求被中止: 未能创建 SSL/TLS 安全通道

  • 1,648 views
  • 阅读模式

最近因为安全性要求:将所有域名TLS版本限制为1.2才能访问,禁用了之前的1.0和1.1。但是在.net后台进行请求时报错“请求被中止: 未能创建 SSL/TLS 安全通道”

通过以下方式解决:

ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

具体原理参考微软官方文档:

https://docs.microsoft.com/zh-cn/dotnet/api/system.net.servicepointmanager.securityprotocol?view=net-5.0

https://support.microsoft.com/zh-cn/topic/%E6%97%A0%E6%B3%95%E8%BF%9E%E6%8E%A5%E5%88%B0%E4%B8%80%E5%8F%B0%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%8D%87%E7%BA%A7%E5%88%B0-net-framework-4-6-%E5%90%8E%E4%BD%BF%E7%94%A8-servicepointmanager-%E6%88%96-sslstream-api-1e3a9788-ab0d-7794-204b-6c4678bc5ed5

weinxin
扫码关注微信公众号--IT老五
微信扫一扫关注公众号,获取更多实用app,订阅地址不定时更新
IT老五
  • 本文由 发表于 2021-08-15 21:35:07
  • 转载请务必保留本文链接:https://itlao5.com/6226.html
评论  0  访客  0
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定