WebRequest:基础连接已关闭 [英] WebRequest: The underlying connection was closed

查看:85
本文介绍了WebRequest:基础连接已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用必须下载一个特定文件,此处是网址.在提供商方面进行了最近的更改后,该应用程序运行良好,持续了数年之久.我得到底层连接已关闭:发送中发生意外错误".

My app has to download one certain file, here is the url. The app worked fine for years bur after a recent change on provider side I'm getting 'The underlying connection was closed: An unexpected error occurred on a send.'

我已经阅读了网上的所有相关信息,但没有建议的修复程序对我有用.

I have read all related info in net but none of suggested fixes works for me.

重要提示:该代码在Net Framework 4.6上可以正常使用,但我需要在3.5上使用.

Important note: the code works OK with Net Framework 4.6 but I need it to work with 3.5.

有什么想法吗?

这是代码:

        var url = new Uri(@"http://www.ezv.admin.ch/pdf_linker.php?doc=edecReceiptResponse_stylesheet_v_3_0");

        var request = (HttpWebRequest)WebRequest.Create(url);
        request.KeepAlive = false;
        request.AllowAutoRedirect = true;
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36";
        request.ProtocolVersion = HttpVersion.Version10;

更新:堆栈:

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream.
   at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest 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.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.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.ConnectStream.WriteHeaders(Boolean async)

另一个更新:使用Fiddler检查了连接到http S 的应用,并将收到的响应与net 4.6(有效)和net 3.5(失败)进行了比较:

one more update: checked with Fiddler the app connecting to httpS and compared responses received with net 4.6 (works) with net 3.5 (fails):

  • 4.6收到两个响应,即5670 + 664785字节
  • 3.5还收到两个响应,每个响应7个字节

推荐答案

按照测试,这是www.ezv.admin.ch支持的协议.

As per conducted test here are the protocols supported by www.ezv.admin.ch.

Protocols
TLS 1.2 Yes
TLS 1.1 No
TLS 1.0 No
SSL 3   No
SSL 2   No

服务器端升级很可能已将安全协议的版本升级为专用的TLS 1.2.

The server side upgrade has most likely upgraded the version of the security protocol to be exclusively TLS 1.2.

按照以下文章 .NET Framework 3.5不支持此版本,您唯一的选择是升级客户端库或修补它们,请参见下文.

As per the following article .NET Framework 3.5 does not support this version and the only options you have is to upgrade your client libraries or patch them, see below.

.NET 3.5或更低版本.不支持TLS 1.2(*),并且没有解决方法.将您的应用程序升级到最新版本的框架.

.NET 3.5 or below. TLS 1.2 is not supported (*) and there is no workaround. Upgrade your application to more recent version of the framework.

有关如何修补客户端以增加支持的更多信息.

Here is some more information of how to patch your client to add support.

P.P.S.如下所述,来自Microsoft的Christian Pop可用于TLS1.2的.NET 3.5的最新修补程序.

P.P.S. As Christian Pop from Microsoft mentioned below, there is a recent patch available for .NET 3.5 which is enabling TLS1.2 support.

请参阅:

KB3154​​518 –可靠性汇总表HR-1605 – NDP 2.0 SP2 – Win7 SP1/Win2008 R2 SP1 KB3154​​519 –可靠性汇总表HR-1605 – NDP 2.0 SP2 –Win8 RTM/Win 2012 RTM KB3154​​520 –可靠性汇总HR-1605 – NDP 2.0SP2 – Win8.1RTM/Win 2012 R2 RTM KB3156421 -1605 HotFix汇总通过Windows 10的Windows更新.

KB3154518 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win7 SP1/Win 2008 R2 SP1 KB3154519 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win8 RTM/Win 2012 RTM KB3154520 – Reliability Rollup HR-1605 – NDP 2.0 SP2 – Win8.1RTM/Win 2012 R2 RTM KB3156421 -1605 HotFix Rollup through Windows Update for Windows 10.

这篇关于WebRequest:基础连接已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆