WebHeaderCollection Class

July 28, 2014

Contains protocol headers associated with a request or response.

System.Object
  System.Net.WebHeaderCollection

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

public sealed class WebHeaderCollection : IEnumerable

The WebHeaderCollection type exposes the following members.

  NameDescription
Public methodWebHeaderCollectionInitializes a new instance of the WebHeaderCollection class.
Top

  NameDescription
Public propertyAllKeysGets the collection of header name/value pairs associated with the request.
Public propertyCountGets the number of headers in the collection.
Public propertyItem[HttpRequestHeader]Gets or sets the specified request header.
Public propertyItem[String]Gets or sets the specified request header.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a String that represents the current WebHeaderCollection. (Overrides Object.ToString().)
Top

  NameDescription
Public Extension MethodAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodCast<TResult>Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate methodIEnumerable.GetEnumeratorReturns an enumerator that can iterate through the WebHeaderCollection instance.
Top

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.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

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

Show:
© 2014 Microsoft