【发布时间】:2017-09-21 05:37:56
【问题描述】:
我的应用程序必须下载一个特定的文件,here is the url。该应用程序在提供者方面最近发生变化后运行良好多年,我得到“底层连接已关闭:发送时发生意外错误。”
我已阅读网络中的所有相关信息,但没有一个建议的修复对我有用。
重要提示:该代码适用于 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 一起检查连接到 httpS 的应用,并将收到的响应与 net 4.6(有效)和 net 3.5(失败)进行比较:
- 4.6 收到两个响应,5670 + 664785 字节
- 3.5 还收到两个响应,每个响应 7 个字节
【问题讨论】:
-
www.ezv.admin.ch关闭连接或者您有通信问题(网络问题/防火墙)。 -
显示其堆栈跟踪
-
请显示来自 Fiddler 或 Wireshark 的 HTTP 请求/响应。
-
@Eugene Komisarenko,看起来服务器没有响应,服务器只是关闭了连接。 Fiddler 只显示请求。
-
也许你正在处理新版本的安全协议,试试这个设置stackoverflow.com/a/12244894/920557