Export (0) Print
Expand All

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.

  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsWebHeaderCollection()Initializes a new instance of the WebHeaderCollection class.
Protected methodWebHeaderCollection(SerializationInfo, StreamingContext)Initializes a new instance of the WebHeaderCollection class from the specified instances of the SerializationInfo and StreamingContext classes.
Top

  NameDescription
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsAllKeysGets all header names (keys) in the collection. (Overrides NameValueCollection.AllKeys.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsCountGets the number of headers in the collection. (Overrides NameObjectCollectionBase.Count.)
Protected propertyIsReadOnlyGets or sets a value indicating whether the NameObjectCollectionBase instance is read-only. (Inherited from NameObjectCollectionBase.)
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsItem[HttpRequestHeader]Gets or sets the specified request header.
Public propertyItem[HttpResponseHeader]Gets or sets the specified response header.
Public propertyItem[Int32]Gets the entry at the specified index of the NameValueCollection. (Inherited from NameValueCollection.)
Public propertyItem[String]Gets or sets the entry with the specified key in the NameValueCollection. (Inherited from NameValueCollection.)
Public propertyKeysGets the collection of header names (keys) in the collection. (Overrides NameObjectCollectionBase.Keys.)
Top

  NameDescription
Public methodAdd(NameValueCollection)Copies the entries in the specified NameValueCollection to the current NameValueCollection. (Inherited from NameValueCollection.)
Public methodAdd(String)Inserts the specified header into the collection.
Public methodAdd(HttpRequestHeader, String)Inserts the specified header with the specified value into the collection.
Public methodAdd(HttpResponseHeader, String)Inserts the specified header with the specified value into the collection.
Public methodAdd(String, String)Inserts a header with the specified name and value into the collection. (Overrides NameValueCollection.Add(String, String).)
Protected methodAddWithoutValidateInserts a header into the collection without checking whether the header is on the restricted header list.
Protected methodBaseAddAdds an entry with the specified key and value into the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseClearRemoves all entries from the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseGet(Int32)Gets the value of the entry at the specified index of the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseGet(String)Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseGetAllKeysReturns a String array that contains all the keys in the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseGetAllValues()Returns an Object array that contains all the values in the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseGetAllValues(Type)Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseGetKeyGets the key of the entry at the specified index of the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseHasKeysGets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null. (Inherited from NameObjectCollectionBase.)
Protected methodBaseRemoveRemoves the entries with the specified key from the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseRemoveAtRemoves the entry at the specified index of the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseSet(Int32, Object)Sets the value of the entry at the specified index of the NameObjectCollectionBase instance. (Inherited from NameObjectCollectionBase.)
Protected methodBaseSet(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 methodClearRemoves all headers from the collection. (Overrides NameValueCollection.Clear().)
Public methodCopyToCopies the entire NameValueCollection to a compatible one-dimensional Array, starting at the specified index of the target array. (Inherited from NameValueCollection.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(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 methodGet(Int32)Get the value of a particular header in the collection, specified by an index into the collection. (Overrides NameValueCollection.Get(Int32).)
Public methodGet(String)Get the value of a particular header in the collection, specified by the name of the header. (Overrides NameValueCollection.Get(String).)
Public methodGetEnumeratorReturns an enumerator that can iterate through the WebHeaderCollection instance. (Overrides NameObjectCollectionBase.GetEnumerator().)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetKeyGet the header name at the specified position in the collection. (Overrides NameValueCollection.GetKey(Int32).)
Public methodGetObjectDataInfrastructure. Populates a SerializationInfo with the data needed to serialize the target object. (Overrides NameObjectCollectionBase.GetObjectData(SerializationInfo, StreamingContext).)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValues(Int32)Gets an array of header values stored in the index position of the header collection. (Overrides NameValueCollection.GetValues(Int32).)
Public methodGetValues(String)Gets an array of header values stored in a header. (Overrides NameValueCollection.GetValues(String).)
Public methodHasKeysGets a value indicating whether the NameValueCollection contains keys that are not null. (Inherited from NameValueCollection.)
Protected methodInvalidateCachedArraysResets the cached arrays of the collection to null. (Inherited from NameValueCollection.)
Public methodStatic memberIsRestricted(String)Tests whether the specified HTTP header can be set for the request.
Public methodStatic memberIsRestricted(String, Boolean)Tests whether the specified HTTP header can be set for the request or the response.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOnDeserializationImplements the ISerializable interface and raises the deserialization event when the deserialization is complete. (Overrides NameObjectCollectionBase.OnDeserialization(Object).)
Public methodRemove(HttpRequestHeader)Removes the specified header from the collection.
Public methodRemove(HttpResponseHeader)Removes the specified header from the collection.
Public methodRemove(String)Removes the specified header from the collection. (Overrides NameValueCollection.Remove(String).)
Public methodSet(HttpRequestHeader, String)Sets the specified header to the specified value.
Public methodSet(HttpResponseHeader, String)Sets the specified header to the specified value.
Public methodSet(String, String)Sets the specified header to the specified value. (Overrides NameValueCollection.Set(String, String).)
Public methodToByteArrayInfrastructure. Converts the WebHeaderCollection to a byte array..
Public methodSupported in .NET for Windows Store appsToStringInfrastructure. This method is obsolete. (Overrides Object.ToString().)
Top

  NameDescription
Public Extension MethodSupported by Portable Class LibrarySupported in .NET for Windows Store appsAsParallelEnables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodSupported by Portable Class LibrarySupported in .NET for Windows Store appsAsQueryableConverts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodSupported by Portable Class LibrarySupported in .NET for Windows Store appsCast<TResult>Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodSupported by Portable Class LibrarySupported in .NET for Windows Store appsOfType<TResult>Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top

  NameDescription
Explicit interface implemetationPrivate methodICollection.CopyToCopies the entire NameObjectCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array. (Inherited from NameObjectCollectionBase.)
Explicit interface implemetationPrivate propertyICollection.IsSynchronizedGets a value indicating whether access to the NameObjectCollectionBase object is synchronized (thread safe). (Inherited from NameObjectCollectionBase.)
Explicit interface implemetationPrivate propertyICollection.SyncRootGets an object that can be used to synchronize access to the NameObjectCollectionBase object. (Inherited from NameObjectCollectionBase.)
Explicit interface implemetationPrivate methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsIEnumerable.GetEnumeratorReturns an enumerator that can iterate through the WebHeaderCollection instance.
Explicit interface implemetationPrivate methodISerializable.GetObjectDataInfrastructure. 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.5.2, 4.5.1, 4.5, 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

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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.
Show:
© 2014 Microsoft