【发布时间】:2023-03-07 11:14:01
【问题描述】:
向我托管的 https:// 网站发出简单的 GET 请求时,我不断收到间歇性 SecureChannelFailure 错误。没有任何错误进入服务器日志文件。每 100 次调用的频率小于 1 次错误,但是下面的代码是否有任何原因会导致这些错误?
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()
错误:
SecureChannelFailure
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
更新: 一直在.net 创建的控制台应用程序中调用它。我无法使用在同一台 Windows 机器上运行的 python 脚本来复制同样的问题。那和微软有关系吗?
【问题讨论】:
标签: c# ssl httprequest