0 out of 1 rated this helpful - Rate this topic

WebHeaderCollection Class

Contains protocol headers associated with a request or response.

Namespace:  System.Net
Assembly:  System (in System.dll)
[SerializableAttribute]
[ComVisibleAttribute(true)]
public class WebHeaderCollection : NameValueCollection, 
	ISerializable

The WebHeaderCollection type exposes the following members.

  Name Description
Public method Supported by Portable Class Library WebHeaderCollection() Initializes a new instance of the WebHeaderCollection class.
Protected method WebHeaderCollection(SerializationInfo, StreamingContext) Initializes a new instance of the WebHeaderCollection class from the specified instances of the SerializationInfo and StreamingContext classes.
Top
  Name Description
Public property Supported by Portable Class Library AllKeys Gets all header names (keys) in the collection. (Overrides NameValueCollection.AllKeys.)
Public property Supported by Portable Class Library Count Gets the number of headers in the collection. (Overrides NameObjectCollectionBase.Count.)
Protected property IsReadOnly Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only. (Inherited from NameObjectCollectionBase.)
Public property Supported by Portable Class Library Item[HttpRequestHeader] Gets or sets the specified request header.
Public property Item[HttpResponseHeader] Gets or sets the specified response header.
Public property Item[Int32] Gets the entry at the specified index of the NameValueCollection. (Inherited from NameValueCollection.)
Public property Item[String] Gets or sets the entry with the specified key in the NameValueCollection. (Inherited from NameValueCollection.)
Public property Keys Gets the collection of header names (keys) in the collection. (Overrides NameObjectCollectionBase.Keys.)
Top
  Name Description
Public method Add(NameValueCollection) Copies the entries in the specified NameValueCollection to the current NameValueCollection. (Inherited from NameValueCollection.)
Public method Add(String) Inserts the specified header into the collection.
Public method Add(HttpRequestHeader, String) Inserts the specified header with the specified value into the collection.
Public method Add(HttpResponseHeader, String) Inserts the specified header with the specified value into the collection.
Public method Add(String, String) Inserts a header with the specified name and value into the collection. (Overrides NameValueCollection.Add(String, String).)
Protected method AddWithoutValidate Inserts a header into the collection without checking whether the header is on the restricted header list.
Protected method BaseAdd Adds an entry with the specified key and value into the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseClear Removes all entries from the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseGet(Int32) Gets the value of the entry at the specified index of the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseGet(String) Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseGetAllKeys Returns a String array that contains all the keys in the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseGetAllValues() Returns an Object array that contains all the values in the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseGetAllValues(Type) Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseGetKey Gets the key of the entry at the specified index of the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseHasKeys Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null. (Inherited from NameObjectCollectionBase.)
Protected method BaseRemove Removes the entries with the specified key from the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseRemoveAt Removes the entry at the specified index of the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseSet(Int32, Object) Sets the value of the entry at the specified index of the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected method BaseSet(String, Object) Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Public method Clear Removes all headers from the collection. (Overrides NameValueCollection.Clear().)
Public method CopyTo Copies the entire NameValueCollection to a compatible one-dimensional Array, starting at the specified index of the target array. (Inherited from NameValueCollection.)
Public method Supported by Portable Class Library Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by Portable Class Library Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Get(Int32) Get the value of a particular header in the collection, specified by an index into the collection. (Overrides NameValueCollection.Get(Int32).)
Public method Get(String) Get the value of a particular header in the collection, specified by the name of the header. (Overrides NameValueCollection.Get(String).)
Public method GetEnumerator Returns an enumerator that can iterate through the WebHeaderCollection instance. (Overrides NameObjectCollectionBase.GetEnumerator().)
Public method Supported by Portable Class Library GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetKey Get the header name at the specified position in the collection. (Overrides NameValueCollection.GetKey(Int32).)
Public method GetObjectData Infrastructure. Populates a SerializationInfo with the data needed to serialize the target object. (Overrides NameObjectCollectionBase.GetObjectData(SerializationInfo, StreamingContext).)
Public method Supported by Portable Class Library GetType Gets the Type of the current instance. (Inherited from Object.)
Public method GetValues(Int32) Gets an array of header values stored in the index position of the header collection. (Overrides NameValueCollection.GetValues(Int32).)
Public method GetValues(String) Gets an array of header values stored in a header. (Overrides NameValueCollection.GetValues(String).)
Public method HasKeys Gets a value indicating whether the NameValueCollection contains keys that are not null. (Inherited from NameValueCollection.)
Protected method InvalidateCachedArrays Resets the cached arrays of the collection to null. (Inherited from NameValueCollection.)
Public method Static member IsRestricted(String) Tests whether the specified HTTP header can be set for the request.
Public method Static member IsRestricted(String, Boolean) Tests whether the specified HTTP header can be set for the request or the response.
Protected method Supported by Portable Class Library MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method OnDeserialization Implements the ISerializable interface and raises the deserialization event when the deserialization is complete. (Overrides NameObjectCollectionBase.OnDeserialization(Object).)
Public method Remove(HttpRequestHeader) Removes the specified header from the collection.
Public method Remove(HttpResponseHeader) Removes the specified header from the collection.
Public method Remove(String) Removes the specified header from the collection. (Overrides NameValueCollection.Remove(String).)
Public method Set(HttpRequestHeader, String) Sets the specified header to the specified value.
Public method Set(HttpResponseHeader, String) Sets the specified header to the specified value.
Public method Set(String, String) Sets the specified header to the specified value. (Overrides NameValueCollection.Set(String, String).)
Public method ToByteArray Infrastructure. Converts the WebHeaderCollection to a byte array..
Public method ToString Infrastructure. This method is obsolete. (Overrides Object.ToString().)
Top
  Name Description
Explicit interface implemetation Private method ICollection.CopyTo Copies the entire NameObjectCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array. (Inherited from NameObjectCollectionBase.)
Explicit interface implemetation Private property ICollection.IsSynchronized Gets a value indicating whether access to the NameObjectCollectionBase object is synchronized (thread safe). (Inherited from NameObjectCollectionBase.)
Explicit interface implemetation Private property ICollection.SyncRoot Gets an object that can be used to synchronize access to the NameObjectCollectionBase object. (Inherited from NameObjectCollectionBase.)
Explicit interface implemetation Private method ISerializable.GetObjectData Infrastructure. Serializes this instance into the specified SerializationInfo object.
Top

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

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ