2017-03-16 187 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服務發出請求。

相關問題