gpt4 book ai didi

c# - 加载某些网站时出现 SSL 错误 "A call to SSPI failed"c#

转载 作者:太空宇宙 更新时间:2023-11-03 13:59:36 25 4
gpt4 key购买 nike

我通过我的 c# 应用程序下载的一些网站似乎抛出异常

A call to SSPI failed

无论我尝试使用何种 SSL 确认组合,我都无法从这些网站下载任何内容。 3m.com 就是一个例子。

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.3m.com");

ServicePointManager.CheckCertificateRevocationList = false;
ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
request.Timeout = 5000;
request.KeepAlive = false;
request.AllowAutoRedirect = true;
request.Accept = "text/html, application/xhtml+xml, application/xml; q=0.9, image/webp, */*; q=0.8";
request.Headers["Accept-Language"] = "en-GB,en-US;q=0.7,en;q=0.3";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();

最佳答案

我终于明白了。

问题是,我在创建 HttpWebRequest 对象后声明了 SSL 选项。

下面的代码有效。

ServicePointManager.CheckCertificateRevocationList = false;
ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
ServicePointManager.ServerCertificateValidationCallback += (senderj, cert, chain, sslPolicyErrors) => true;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.3m.com");

request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
request.Timeout = 5000;
request.KeepAlive = false;
request.AllowAutoRedirect = true;
request.Accept = "text/html, application/xhtml+xml, application/xml; q=0.9, image/webp, */*; q=0.8";
request.Headers["Accept-Language"] = "en-GB,en-US;q=0.7,en;q=0.3";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();

关于c# - 加载某些网站时出现 SSL 错误 "A call to SSPI failed"c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55091117/

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