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