2017-12-18 32 views
0

私はこのコードをサーバに簡単な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.

しかし、過去のサービスは問題なく成功したこと、 何が起こった?どうすれば問題を解決できますか?

+0

ヘッダー、または提供していないコンテンツの種類が必要なのかもしれません。これはAPIプロバイダとそのドキュメントに対してチェックされますが、何が間違っているのかはわかりません。 –

答えて

0

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を使用していることを確認してください。

関連する問題