I'm trying to send the same information from my application as I send from the browser. Here is part of data captured by Fiddler:
POST http://something/ HTTP/1.1
Host: something.com
Connection: keep-alive
I got stuck with this connection property. If I set the property keep-alive to true, in Fiddler I see this:
Proxy-Connection: Keep-Alive
If I try to set the connection property to Keep-alive, I get this error:
Keep-Alive and Close may not be set using this property.
How to write the code so that in Fiddler I can see this:
Connection: keep-alive
My full code:
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();
The Connection general header controls whether the network connection stays open after the current transaction finishes. If the value sent is keep-alive , the connection is persistent and not closed, allowing for subsequent requests to the same server to be done.
The fast answer no "No". Keep-Alive headers are HTTP 1.0 syntax and are not included i the HTTP 1.1 definition. HTTP 1.1 defaults to persistent connections, and does not need a mechanism to request them.
The time (in seconds) before idle keep-alive connections are closed. Set this value in the Admin Console in the Timeout field on the configuration's Performance tab ⇒ HTTP tab, under Keep Alive Settings. The default is 30 seconds, meaning the connection times out if idle for more than 30 seconds.
To have your application send a Connection: Keep-Alive
header, use the KeepAlive property on the HttpWebRequest
object.
When a client knows that it is behind a proxy (like Fiddler), it may send a Proxy-Connection: Keep-Alive
header instead of a Connection: Keep-Alive
header. The expectation is that a HTTP/1.1 proxy (like Fiddler) will convert that header from Proxy-Connection
to Connection
before passing it to the upstream server.
This "proxy renames header" pattern was introduced many years ago to attempt to workaround hangs in HTTP/1.0 servers that didn't support Keep-Alive
properly; the idea is that the server would ignore the Proxy-Connection
header if the outdated proxy didn't rename the header by removing the Proxy-
prefix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With