System.Net.HttpWebRequest.Connection Property

Gets or sets the value of the Connection HTTP header.


public string Connection { get; set; }


A string containing the value of the Connection HTTP header. The default value is null.


ArgumentExceptionThe value of HttpWebRequest.Connection is set to "Keep-alive" or "Close". This value is case insensitive.


The request sends the HttpWebRequest.Connection property to the Internet resource as the Connection HTTP header. If the value of the HttpWebRequest.KeepAlive property is true, the value "Keep-alive" is appended to the end of the Connection header.

To clear the Connection HTTP header, set the HttpWebRequest.Connection property to null.

Changing the HttpWebRequest.Connection property after the request has been started by calling the HttpWebRequest.GetRequestStream, HttpWebRequest.BeginGetRequestStream(AsyncCallback, object), HttpWebRequest.GetResponse, or HttpWebRequest.BeginGetResponse(AsyncCallback, object) method throws an InvalidOperationException.


The value for this property is stored in System.Net.WebHeaderCollection. If WebHeaderCollection is set, the property value is lost.


Namespace: System.Net
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0,,