偶爾遇到的“The request was aborted:Could not create SSL/TLS secure channel.”怎么解決?


項目中涉及到調用第三方的Https的WebService,我使用的是原始的HttpWebRequest。

代碼中已經考慮到是Https,加上了SSL3協議,加上了委托調用。但偶爾還是會碰到

The request was aborted:Could not create SSL/TLS secure channel.

這樣的錯誤。

於是根據這篇博客所說,將其改成使用Tls協議,看看有沒有用。

            if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))///https請求
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; //SSL3協議替換成TLS協議
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                webRequest = WebRequest.Create(url) as HttpWebRequest;
                webRequest.ProtocolVersion = HttpVersion.Version10;
            }
            else
            {
                webRequest = WebRequest.Create(url) as HttpWebRequest;
            }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM