HttpWebRequest closed connection was closed

I use HttpWebRequest to POST image of a byte array through web services, image size is approximately similar to byte[4096]

code:

 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(wsHost); webRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate"); webRequest.Headers.Add(HttpRequestHeader.KeepAlive, "true"); 

I get an error message:

 The underlying connection was closed. A connection that was expected to be kept alive was closed by the server 

Is this a server problem, or is my sending problem?

+4
source share
1 answer

It can be a lot of things. Can you connect to the server otherwise?

If so, try disabling the Expected 100 Continue (before you do your POST) through

 System.Net.ServicePointManager.Expect100Continue = false; 

According to HTTP 1.1, when this header is submitted, form data is not submitted with the initial request. Instead, this header is sent to the web server, which answers 100 (Continue) if it is executed correctly. However, not all web servers handle this correctly, including the server to which I am trying to send data.

via http://haacked.com/archive/2004/05/15/http-web-request-expect-100-continue.aspx

If this does not work with another resource: http://geekswithblogs.net/Denis/archive/2005/08/16/50365.aspx suggests that many have decided by processing their requests as HTTP 1.0 requests:

 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(wsHost); webRequest.KeepAlive = false; webRequest.ProtocolVersion=HttpVersion.Version10; 
+6
source

Source: https://habr.com/ru/post/1443561/


All Articles