WebHeaderCollection WebHeaderCollection WebHeaderCollection WebHeaderCollection Class

Definition

Contains protocol headers associated with a request or response.

public ref class WebHeaderCollection : System::Collections::Specialized::NameValueCollection, System::Runtime::Serialization::ISerializable
[System.Runtime.InteropServices.ComVisible(true)]
public class WebHeaderCollection : System.Collections.Specialized.NameValueCollection, System.Runtime.Serialization.ISerializable
type WebHeaderCollection = class
    inherit NameValueCollection
    interface ISerializable
Public Class WebHeaderCollection
Inherits NameValueCollection
Implements ISerializable
Inheritance
WebHeaderCollectionWebHeaderCollectionWebHeaderCollectionWebHeaderCollection
Attributes
Implements

Remarks

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

Constructors

WebHeaderCollection() WebHeaderCollection() WebHeaderCollection() WebHeaderCollection()

Initializes a new instance of the WebHeaderCollection class.

WebHeaderCollection(SerializationInfo, StreamingContext) WebHeaderCollection(SerializationInfo, StreamingContext) WebHeaderCollection(SerializationInfo, StreamingContext) WebHeaderCollection(SerializationInfo, StreamingContext)

Initializes a new instance of the WebHeaderCollection class from the specified instances of the SerializationInfo and StreamingContext classes.

Properties

AllKeys AllKeys AllKeys AllKeys

Gets all header names (keys) in the collection.

Count Count Count Count

Gets the number of headers in the collection.

Item[HttpRequestHeader] Item[HttpRequestHeader] Item[HttpRequestHeader] Item[HttpRequestHeader]

Gets or sets the specified request header.

Item[HttpResponseHeader] Item[HttpResponseHeader] Item[HttpResponseHeader] Item[HttpResponseHeader]

Gets or sets the specified response header.

Item[String] Item[String] Item[String] Item[String]
Keys Keys Keys Keys

Gets the collection of header names (keys) in the collection.

Methods

Add(HttpRequestHeader, String) Add(HttpRequestHeader, String) Add(HttpRequestHeader, String) Add(HttpRequestHeader, String)

Inserts the specified header with the specified value into the collection.

Add(HttpResponseHeader, String) Add(HttpResponseHeader, String) Add(HttpResponseHeader, String) Add(HttpResponseHeader, String)

Inserts the specified header with the specified value into the collection.

Add(String) Add(String) Add(String) Add(String)

Inserts the specified header into the collection.

Add(String, String) Add(String, String) Add(String, String) Add(String, String)

Inserts a header with the specified name and value into the collection.

AddWithoutValidate(String, String) AddWithoutValidate(String, String) AddWithoutValidate(String, String) AddWithoutValidate(String, String)

Inserts a header into the collection without checking whether the header is on the restricted header list.

Clear() Clear() Clear() Clear()

Removes all headers from the collection.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Get(Int32) Get(Int32) Get(Int32) Get(Int32)

Gets the value of a particular header in the collection, specified by an index into the collection.

Get(String) Get(String) Get(String) Get(String)

Gets the value of a particular header in the collection, specified by the name of the header.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator that can iterate through the WebHeaderCollection instance.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetKey(Int32) GetKey(Int32) GetKey(Int32) GetKey(Int32)

Gets the header name at the specified position in the collection.

GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext) GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data needed to serialize the target object.

GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValues(Int32) GetValues(Int32) GetValues(Int32) GetValues(Int32)

Gets an array of header values stored in the index position of the header collection.

GetValues(String) GetValues(String) GetValues(String) GetValues(String)

Gets an array of header values stored in a header.

IsRestricted(String) IsRestricted(String) IsRestricted(String) IsRestricted(String)

Tests whether the specified HTTP header can be set for the request.

IsRestricted(String, Boolean) IsRestricted(String, Boolean) IsRestricted(String, Boolean) IsRestricted(String, Boolean)

Tests whether the specified HTTP header can be set for the request or the response.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialization(Object) OnDeserialization(Object) OnDeserialization(Object) OnDeserialization(Object)

Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.

Remove(HttpRequestHeader) Remove(HttpRequestHeader) Remove(HttpRequestHeader) Remove(HttpRequestHeader)

Removes the specified header from the collection.

Remove(HttpResponseHeader) Remove(HttpResponseHeader) Remove(HttpResponseHeader) Remove(HttpResponseHeader)

Removes the specified header from the collection.

Remove(String) Remove(String) Remove(String) Remove(String)

Removes the specified header from the collection.

Set(HttpRequestHeader, String) Set(HttpRequestHeader, String) Set(HttpRequestHeader, String) Set(HttpRequestHeader, String)

Sets the specified header to the specified value.

Set(HttpResponseHeader, String) Set(HttpResponseHeader, String) Set(HttpResponseHeader, String) Set(HttpResponseHeader, String)

Sets the specified header to the specified value.

Set(String, String) Set(String, String) Set(String, String) Set(String, String)

Sets the specified header to the specified value.

ToByteArray() ToByteArray() ToByteArray() ToByteArray()

Converts the WebHeaderCollection to a byte array..

ToString() ToString() ToString() ToString()

This method is obsolete.

Explicit Interface Implementations

IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()
ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Serializes this instance into the specified SerializationInfo object.

Applies to