System.Net.HttpWebRequest.Connection Property

Gets or sets the value of the Connection HTTP header.

Syntax

public string Connection { get; set; }

Value

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

Exceptions

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

Remarks

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.

Note:

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

Requirements

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