WebHeaderCollection Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Contains protocol headers associated with a request or response.

Inheritance Hierarchy

System..::.Object
System.Net..::.WebHeaderCollection

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

Syntax

Public NotInheritable Class WebHeaderCollection _
    Implements IEnumerable
public sealed class WebHeaderCollection : IEnumerable

The WebHeaderCollection type exposes the following members.

Constructors

Name Description
WebHeaderCollection Initializes a new instance of the WebHeaderCollection class.

Top

Properties

Name Description
AllKeys Gets the collection of header name/value pairs associated with the request.
Count Gets the number of headers in the collection.
Item[([(HttpRequestHeader])]) Gets or sets the specified request header.
Item[([(String])]) Gets or sets the specified request header.

Top

Methods

Name Description
Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
GetType Gets the Type of the current instance. (Inherited from Object.)
MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
ToString Returns a String that represents the current WebHeaderCollection. (Overrides Object..::.ToString()()().)

Top

Extension Methods

Name Description
AsQueryable Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Cast<(Of <(TResult>)>) Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
OfType<(Of <(TResult>)>) Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)

Top

Explicit Interface Implementations

Name Description
IEnumerable..::.GetEnumerator Returns an enumerator that can iterate through the WebHeaderCollection instance.

Top

Remarks

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.

For security reasons, sending specific headers to a cross-domain site is restricted unless the header is allowed by the security policy applicable to the target cross-domain site. This restriction applies to resources from locations other than the site of origin. The Authorization header can be set using the Headers property. However to set the credentials properly, the cross-domain policy applicable to the target must have the http-request-headers set to allow the Authorization header to be sent.

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.

Capabilities

If you use this API in your app, you must specify the following capabilities in the app manifest. Otherwise, your app might not work correctly or it might exit unexpectedly.

ID_CAP_NETWORKING

Windows Phone 8, Windows Phone OS 7.1

For more info, see App capabilities and hardware requirements for Windows Phone 8.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Net Namespace