2017-03-16 128 views
1

我将一些数据发布到服务器,但应用程序正在抛出异常。 这是代码。System.Net.WebException:底层连接已关闭:发送出现意外错误

 ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 

     Dim bytes As Byte() = Encoding.UTF8.GetBytes(xml) 
     Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest) 
     request.Method = "POST" 
     request.ContentLength = bytes.Length 
     request.ContentType = "text/xml" 
     Using requestStream As Stream = request.GetRequestStream() 
      requestStream.Write(bytes, 0, bytes.Length) 
     End Using 

这是异常堆栈跟踪。

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.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.runTryCode(Object userData) 
    at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData) 
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) 
    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.GetRequestStream(TransportContext& context) 
    at System.Net.HttpWebRequest.GetRequestStream() 

我已更新我的代码,根据答案/ s here但无济于事。我还检查了代理服务器已断开连接。

回答

1

我能够发现我是POST的服务器只接受具有安全协议TLS 1.1及更高版本的请求。该应用程序运行在仅支持SSL和TLS 1.0协议的.NET 3.5上。解决方案是将应用程序升级到.NET 4.5,并使用TLS 1.1及更高版本向HTTP服务发出请求。

相关问题