WebHeaderCollection.Item Property (String)
Gets or sets the specified request header.
Assembly: System.Net (in System.Net.dll)
The name parameter contains illegal characters- or -
The name parameter was null.
On a get or set operation, the request header specified in the name 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 property can be used to get or set the value of a header for use by WebClient or HttpWebRequest classes. The property can be used to get the value of custom header or a header not defined in the HttpRequestHeader enumeration for use by the WebClient or HttpWebRequest classes. The property can also be used to get the value of a common header defined in the HttpRequestHeader enumeration by passing the string of the common header name as the name parameter.
The property can also be used to set the name and value for header. When setting a header, both a name and value parameter must be passed in as strings
Some headers 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 using the property 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.