C#4.0 HTTP协议无法使用TLS1.2的问题


问题:当https  协议只支持 TLS 1.2 版本以上协议的时候。常规的   get  post  请求将会失败: 

报错信息:请求被中止: 未能创建 SSL/TLS 安全通道 4.0

 

解决方案:

在发送HTTP请求前加入下行代码

ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

如果是4.5以上版本可以直接使用

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;

 

 

TLS 协议解释:https://blog.csdn.net/mrpre/article/details/77978293


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM