WebHeaderCollection.Item Property (HttpRequestHeader)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets or sets the specified request header.

Namespace: System.Net
Assembly: System.Net (in System.Net.dll)


Public Property Item ( _
    header As HttpRequestHeader _
) As String
public string this[
    HttpRequestHeader header
] { get; set; }


Property Value

Type: System..::.String
A String instance containing the specified header value.


Exception Condition

On a get or set operation, the request header specified in the header parameter is a restricted header. The WebHeaderCollection class does not allow a user to get or set instances of this restricted header in this WebHeaderCollection instance.


The Item[([(HttpRequestHeader])]) property can be used to get the value of a common header defined in the HttpRequestHeader enumeration for use by WebClient or HttpWebRequest classes.

The Item[([(String])]) property can also be used to set the name and value for a header in a WebHeaderCollection. When setting a header, both a header and value parameter must be passed. The value parameter must be specified as a string.

Some common headers defined in the HttpRequestHeader enumeration are considered restricted and are either exposed directly (such as Content-Type) or protected by the system and cannot be set in a WebHeaderCollection object. Any attempt to set one of these restricted headers in the WebHeaderCollection object throws an exception. If the WebHeaderCollection object is associated with a HttpWebRequest object, the exception is thrown by the Item[([(HttpRequestHeader])]) property. If the WebHeaderCollection object is associated with a WebClient object, the exception is thrown later when an attempt to send the WebClient request occurs.

For a list of restricted headers, see the Remarks in the WebHeaderCollection class.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


WebHeaderCollection Class

Item Overload

System.Net Namespace