Aracılığıyla paylaş


WebHeaderCollection.Item Property (HttpRequestHeader)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the specified request header.

Namespace:  System.Net
Assembly:  System.Net (in System.Net.dll)

Syntax

'Declaration
Public Property Item ( _
    header As HttpRequestHeader _
) As String
public string this[
    HttpRequestHeader header
] { get; set; }

Parameters

Property Value

Type: System.String
A String instance containing the specified header value.

Exceptions

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.

Remarks

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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.