Gets or sets the specified request header.
Namespace: System.Net
Assembly: System.Net (in System.Net.dll)
Public Property Item ( _ name As String _ ) As String
public string this[ string name ] { get; set; }
Parameters
- name
- Type: System.String
The name of the requested header.
| Exception | Condition |
|---|---|
| ArgumentException |
The name parameter contains illegal characters- or - an attempt was made to set a restricted header on the WebHeaderCollection object associated with a HttpWebRequest object |
| ArgumentNullException |
The name parameter was null. |
| InvalidOperationException |
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 Item[String] property can be used to get or set the value of a header for use by WebClient or HttpWebRequest classes. The Item[String] 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 Item[String] 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 Item[String] 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 Item[String] 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.
Silverlight
Supported in: 5, 4, 3Silverlight for Windows Phone
Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0XNA Framework
Supported in: Windows Phone OS 7.0For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.