Reputation: 811
I keep getting an intermittent SecureChannelFailure error when making a simple GET request to an https:// website I host. None of the errors are making it into the server log files. The frequency is less than 1 error per 100 calls but is there any reason why the code below would be causing these errors?
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36";
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, image/gif, */*;q=0.8, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-silverlight, */*";
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate,sdch");
request.Proxy = null;
request.AllowAutoRedirect = autoRedirect;
request.Headers.Add("Upgrade-Insecure-Requests", "1");
HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
request.CachePolicy = noCachePolicy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse()
The error:
SecureChannelFailure
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
Update: Had been calling in this in a .net created console app. I can't replicate the same problem using a python script running on the same windows machine. Something to do with microsoft then?
Upvotes: 3
Views: 604
Reputation: 143
Got through the same issue and it occurred about 1% of the time too...
It worked better after removing older security protocols, just keeping TLS 1.2
try instead:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Upvotes: 1