【发布时间】:2018-02-02 22:20:53
【问题描述】:
我们正在开发一个与肥皂网络服务通信的 .Net 应用程序(为 .net 4.0 编译)。
在检索 http Web 响应内容时,该应用程序在多台机器上运行良好。但是,在其中一台机器(Windows Server 2008 R2)上,应用程序无法检索响应。这是一个代码示例:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://200.57.3.82:3443/AdministradorQr/WebServiceDodaPort?wsdl");
request.Method = "GET";
WebResponse response;
Stream responseStream = response.GetResponseStream();
string result = string.Empty;
using (StreamReader streamReader = new StreamReader(responseStream))
{
result = streamReader.ReadToEnd();
}
我们得到的异常是:
The underlying connection was closed: An unexpected error occurred on a send. System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a send. ---> System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.TlsStream.CallProcessAuthentication(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
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)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
问题是,使用具有不同 URL 的相同代码,我们得到了成功的响应,并且问题只发生在一台机器上,即使有另一台机器也使用 Windows 2008 工作得很好。
目前我们无法升级 .net 框架以尝试使用在某些地方找到的解决方案,例如使用 TLS 1.2:"The underlying connection was closed: An unexpected error occurred on a send." With SSL Certificate
正如我所提到的,同样的代码在使用相同 Windows/.net 版本的其他机器上也能正常工作是很奇怪的,而且对于像 http://www.yahoo.com 这样的其他 URL 也能正常工作也很奇怪
【问题讨论】:
-
这台机器上是否安装了杀毒软件?禁用后可以试试吗?
-
我们已安装 McAfee...我们禁用了实时保护并进行了测试,但仍然遇到相同的异常
-
我们也尝试了.net framework 4.0的解决方案,使用ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;但是,如果我们使用它,我们会收到一条错误消息,指出不支持指定的协议
标签: c# httpwebrequest webexception