gpt4 book ai didi

c# - HttpWebrequest 的另一个失败,内部异常身份验证失败,因为远程方已关闭传输流

转载 作者:行者123 更新时间:2023-11-30 20:20:55 24 4
gpt4 key购买 nike

我知道之前有人问过这个问题,但在这些情况下建议的解决方案对我不起作用。我有一个简单的控制台应用程序,可以从网站上抓取数据。昨晚他们更新了安全设置,因此我的代码不再有效。

这是我尝试使用的代码片段:

try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
var request2 = WebRequest.Create("https://www.eex-transparency.com/") as HttpWebRequest;
request2.Method = "GET";
request2.Accept = "text/html, application/xhtml+xml, */*";
request2.Headers.Set(HttpRequestHeader.AcceptLanguage, "en-gb");
request2.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request2.Headers.Add("DNT", "1");
request2.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
request2.Host = "www.eex-transparency.com";
request2.KeepAlive = true;
request2.Headers.Set(HttpRequestHeader.CacheControl, "no-cache");
request2.Proxy = ProxyFactory.GetWebProxy();
using (var response = request2.GetResponse())
{}
}
catch (Exception ex)
{ Console.WriteLine(ex);}

我收到的错误是:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Authentication failed becausethe remote party has closed the transport stream.

at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)

at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocol Request asyncRequest)

at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, A syncProtocolRequest asyncRequest)

at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)

at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)

at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)

at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)

at System.Net.ConnectStream.WriteHeaders(Boolean async)

--- End of inner exception stack trace ---

任何帮助将不胜感激。

提前致谢。

最佳答案

此特定网址仅支持 TLS 版本 1.1 和 1.2。添加了以下代码以使其正常工作:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;

确保您使用的是 Framework 4.5 或更高版本

关于c# - HttpWebrequest 的另一个失败,内部异常身份验证失败,因为远程方已关闭传输流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35087408/

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