The WebHeaderCollection class is generally accessed through WebRequest..::.Headers property.
The Item property can be used to get the value of a header stored in a WebHeaderCollection object. The Item[([(HttpRequestHeader])]) property can be used to get the value of common headers defined in the HttpRequestHeader enumeration. The Item[([(String])]) property can be used to get the value of custom headers and those headers not defined in the HttpRequestHeader enumeration.
The Item property can be used to set custom headers in a WebHeaderCollection object for use by the WebClient or HttpWebRequest objects.
Some common headers are considered restricted and are either exposed directly (such as Content-Type) or protected by the system and cannot be set or changed in a WebHeaderCollection object. Any attempt to set one of these restricted headers in the WebHeaderCollection object associated with a HttpWebRequest object throws an exception. Any attempt to set one of these restricted headers in the WebHeaderCollection object associated with a WebClient object will throw an exception later when attempting to send the WebClient request.
Restricted headers include, but are not limited to the following:
Many of these restricted headers are set by the web browser that hosts the Silverlight application.
In addition, some headers are also restricted when the Method property is set to an HTTP GET protocol verb. These restricted headers include, but are not limited to the following:
Content-Encoding
Content-Language
Content-Location
Content-MD5
Content-Range
Content-Type
Expires
Last-Modified
In addition, some headers are also restricted when the Method property is set to an HTTP POST protocol verb. These restricted headers include, but are not limited to the following:
Content-Location
Content-Range
Last-Modified
You should not assume that the header values will remain unchanged, because Web servers and caches may change or add headers to a Web request.