• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

为什么我得到“连接意外关闭” – Web请求中的错误?

c/c++ 来源:behzad 3次浏览

我想张贴简单的JSON到服务器使用此代码:
为什么我得到“连接意外关闭” – Web请求中的错误?

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://ipaddress:1237"); 
httpWebRequest.ContentType = "application/json"; 
httpWebRequest.Method = "POST"; 
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) 
{ 
    string json = "{'params': {'auth_remoteaddr': '10.10.5.103', 'auth_type': 'ANONYMOUS', 'auth_name': 'ANONYMOUS', 'auth_pass': 'ANONYMOUS', 'login_auth_name': 'crm', 'login_auth_pass': 'crm1234', 'create_session': true, 'login_auth_type': 'ADMIN'}, 'method': 'login.login'}"; 
    streamWriter.Write(json); 
    streamWriter.Flush(); 
    streamWriter.Close(); 
} 
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); 
using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) 
{ 
    var result = streamReader.ReadToEnd(); 
} 

但是,当运行代码,得到了这个错误:

Additional information: The underlying connection was closed: The connection was closed unexpectedly.

但在过去该服务成功没有问题, 发生了什么?我如何解决这个问题?


===========解决方案如下:

This problem occurs when the server or another network device unexpectedly closes an existing Transmission Control Protocol (TCP) connection. This problem may occur when a time-out value on the server or on the network device is set too low. To resolve this problem, see resolutions A, D, E, F, and O. The problem can also occur if the server resets the connection unexpectedly, such as if an unhandled exception crashes the server process. Analyze the server logs to see if this may be the issue.

要解决此问题,请确保您使用的是最新版本的.NET Framework。


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)