WebHeaderCollection Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Contains protocol headers associated with a request or response.


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

type WebHeaderCollection =  class end

The WebHeaderCollection type exposes the following members.

Public methodWebHeaderCollectionInitializes a new instance of the WebHeaderCollection class.

Public propertyAllKeysGets all header names (keys) in the collection.
Public propertyCountGets the number of headers in the collection.
Public propertyItemReturns the string value for the header.

Public methodAdd(String)Inserts the specified header into the collection.
Public methodAdd(String, String)Inserts a header with the specified name and value into the collection.
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 it 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.)
Public methodGetValuesGets an array of header values stored in a header.
Public methodStatic memberIsRestrictedTests whether the specified HTTP header can be set for the request.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodRemoveRemoves the specified header from the collection.
Public methodSetSets the specified header to the specified value.
Public methodToByteArrayInfrastructure. Converts the WebHeaderCollection to a byte array..
Public methodToStringInfrastructure. This method is obsolete. (Overrides Object..::..ToString()()()().)

The WebHeaderCollection class is generally accessed through WebRequest..::..Headers or WebResponse..::..Headers. Some common headers are considered restricted and are either exposed directly by the API (such as Content-Type) or protected by the system and cannot be changed.

The restricted headers are:

  • Accept

  • Connection

  • Content-Length

  • Content-Type

  • Date

  • Expect

  • Host

  • If-Modified-Since

  • Range

  • Referer

  • Transfer-Encoding

  • User-Agent

  • Proxy-Connection

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