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

我想张贴简单的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。

以上是 为什么我得到“连接意外关闭” - Web请求中的错误? 的全部内容, 来源链接: utcz.com/qa/261760.html

回到顶部