WebHeaderCollection.Item Property (HttpRequestHeader)
February 14, 2014
Gets or sets the specified request header.
Assembly: System.Net (in System.Net.dll)
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 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.