Send connection header set as keep-alive

I am trying to send the same information from my application as I am sending from a browser. Here is some of the data captured by Fiddler:

POST http://something/ HTTP/1.1 Host: something.com Connection: keep-alive 

I am stuck with this join property. If I set the keep-alive property to true, in Fiddler I see the following:

Proxy Connection: Keep-Alive

If I try to set the Keep-alive connection property, I get this error:

Keep-Alive and Close cannot be set using this property.

How to write code so that in Fiddler I can see this:

Connection: keep-alive

My full code is:

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://myUrl "); request.Method = "POST"; request.ProtocolVersion = HttpVersion.Version11; request.Accept = "*/*"; WebHeaderCollection headers = new WebHeaderCollection(); headers.Add("Accept-Encoding", "myEncoding"); headers.Add("Accept-Language", "myLang"); request.Headers = headers; request.ContentType = "myContentType"; request.Referer = "myReferer"; request.UserAgent = "myUserAgent"; ASCIIEncoding encoding = new ASCIIEncoding(); string postData = "myData"; byte[] data = encoding.GetBytes(postData); request.GetResponse().Close(); 
+4
source share
1 answer

To have your application send the Connection: Keep-Alive header, use the KeepAlive property of the HttpWebRequest .

When a client knows that it is behind a proxy (for example, Fiddler), it can send the Proxy-Connection: Keep-Alive header instead of the Connection: Keep-Alive header. An HTTP / 1.1 proxy server (such as Fiddler) is expected to convert this header from Proxy-Connection to Connection before transferring it to the upstream server.

This "header rename proxy" template was introduced many years ago to attempt workarounds on HTTP / 1.0 servers that did not support Keep-Alive correctly; the idea is that the server will ignore the Proxy-Connection header if the outdated proxy has not renamed the header by removing the Proxy- prefix.

+9
source

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


All Articles