gpt4 book ai didi

c# - 间歇性 SecureChannelFailure 错误

转载 作者:行者123 更新时间:2023-12-04 22:35:35 25 4
gpt4 key购买 nike

在向我托管的 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 脚本来复制相同的问题。那么与微软有关吗?

最佳答案

遇到了同样的问题,它也发生了大约 1% 的时间......

删除旧的安全协议(protocol)后效果更好,只保留 TLS 1.2

试试看:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

关于c# - 间歇性 SecureChannelFailure 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49049843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com