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

Eli*_*ias 2 c# ssl

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

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

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);}
Run Code Online (Sandbox Code Playgroud)

我收到的错误是:

System.Net.WebException:基础连接已关闭:发送时发生意外错误.---> System.IO.IOException:身份验证失败,因为远程方已关闭传输流.

在System.Net.Security.SslState.StartReadFrame(Byte []缓冲区,Int32 readBytes,AsyncProtocolRequest asyncRequest)

在System.Net.Security.SslState.StartReceiveBlob(Byte []缓冲区,AsyncProtocol请求asyncRequest)

在System.Net.Security.SslState.StartSendBlob(Byte []传入,Int32计数,一个syncProtocolRequest asyncRequest)

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

在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)

在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)

在System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult结果)

在System.Net.TlsStream.Write(Byte []缓冲区,Int32偏移量,Int32大小)

在System.Net.ConnectStream.WriteHeaders(布尔异步)

---内部异常堆栈跟踪结束---

任何帮助将不胜感激.

提前致谢.

Eli*_*ias 7

此特定URL仅支持TLS版本1.1和1.2.添加以下代码以使其工作:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
Run Code Online (Sandbox Code Playgroud)

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