項目中涉及到調用第三方的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; }