2017-04-24 184 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

相關問題