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.
Assembly: System.Net (in System.Net.dll)
Parameters
- header
- Type: System.Net.HttpRequestHeader
The request header value.
| Exception | Condition |
|---|---|
| InvalidOperationException | 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.