2017-04-24 139 views
1

我的应用必须下载某个文件here is the url。这个应用程序在提供商端最近发生的变化之后可以正常工作多年。我得到'底层连接已关闭:发送时发生意外错误。WebRequest:底层连接已关闭

我已阅读所有相关的信息在网络中,但没有建议的修复程序适用于我。

重要说明:Net Framework 4.6的代码工作正常,但我需要它与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 小号该应用和比较响应收到净4.6(工程)净3.5(失败):

  • 4.6接收两个应答,5670个+ 664785字节
  • 3.5还接收两个响应,7个字节每个
+0

要么'www.ezv.admin。ch'关闭连接或者您有通信问题(网络问题/防火墙)。 – bradbury9

+0

显示其堆栈跟踪 –

+0

请显示来自Fiddler或Wireshark的HTTP请求/响应。 –

回答

3

作为每进行test这里是由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。

根据以下内容article .NET Framework 3.5不支持此版本,并且您拥有的唯一选项是升级客户端库或对其进行修补,请参见下文。

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

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

P.P.S.正如微软的Christian Pop在下面提到的那样,最近有一个可用于.NET 3.5的补丁,它支持TLS1.2。

参见:

KB3154​​518 - 可靠性汇总HR-1605 - NDP 2.0 SP2 - Win7的SP1 /赢 2008 R2 SP1 KB3154​​519 - 可靠性汇总HR-1605 - NDP 2.0 SP2 - Win8的RTM /赢2012 RTM KB3154​​520 - 可靠性汇总HR-1605 - 2.0 NDP SP2 - Win8.1RTM /赢2012 R2 RTM KB3156421 -1605修补程序汇总通过 视窗更新的Windows 10

+0

好的。现在一切都很清楚。非常感谢您的帮助。 – sergio

相关问题