Editare

Partajați prin


WebHeaderCollection Class

Definition

Contains protocol headers associated with a request or response.

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

Remarks

The WebHeaderCollection class is generally accessed through WebRequest.Headers or WebResponse.Headers.

On .NET Framework, 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. This does not apply to .NET Core and .NET 5+, where none of the headers are restricted.

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()

Initializes a new instance of the WebHeaderCollection class.

WebHeaderCollection(SerializationInfo, StreamingContext)
Obsolete.

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

Properties

AllKeys

Gets all header names (keys) in the collection.

Count

Gets the number of headers in the collection.

IsReadOnly

Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only.

(Inherited from NameObjectCollectionBase)
Item[HttpRequestHeader]

Gets or sets the specified request header.

Item[HttpResponseHeader]

Gets or sets the specified response header.

Item[Int32]

Gets the entry at the specified index of the NameValueCollection.

(Inherited from NameValueCollection)
Item[String]
Item[String]

Gets or sets the entry with the specified key in the NameValueCollection.

(Inherited from NameValueCollection)
Keys

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

Methods

Add(HttpRequestHeader, String)

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

Add(HttpResponseHeader, String)

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

Add(NameValueCollection)

Copies the entries in the specified NameValueCollection to the current NameValueCollection.

(Inherited from NameValueCollection)
Add(String, String)

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

Add(String)

Inserts the specified header into the collection.

AddWithoutValidate(String, String)

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

BaseAdd(String, Object)

Adds an entry with the specified key and value into the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseClear()

Removes all entries from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGet(Int32)

Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGet(String)

Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllKeys()

Returns a String array that contains all the keys in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllValues()

Returns an Object array that contains all the values in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllValues(Type)

Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetKey(Int32)

Gets the key of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseHasKeys()

Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null.

(Inherited from NameObjectCollectionBase)
BaseRemove(String)

Removes the entries with the specified key from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseRemoveAt(Int32)

Removes the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseSet(Int32, Object)

Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
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)
Clear()

Removes all headers from the collection.

Clear()

Invalidates the cached arrays and removes all entries from the NameValueCollection.

(Inherited from NameValueCollection)
CopyTo(Array, Int32)

Copies the entire NameValueCollection to a compatible one-dimensional Array, starting at the specified index of the target array.

(Inherited from NameValueCollection)
Equals(Object)

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

(Inherited from Object)
Get(Int32)

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

Get(String)

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

GetEnumerator()

Returns an enumerator that can iterate through the WebHeaderCollection instance.

GetEnumerator()

Returns an enumerator that iterates through the NameObjectCollectionBase.

(Inherited from NameObjectCollectionBase)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetKey(Int32)

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

GetObjectData(SerializationInfo, StreamingContext)
Obsolete.

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

GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValues(Int32)

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

GetValues(String)

Gets an array of header values stored in a header.

HasKeys()

Gets a value indicating whether the NameValueCollection contains keys that are not null.

(Inherited from NameValueCollection)
InvalidateCachedArrays()

Resets the cached arrays of the collection to null.

(Inherited from NameValueCollection)
IsRestricted(String, Boolean)

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

IsRestricted(String)

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

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialization(Object)

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

Remove(HttpRequestHeader)

Removes the specified header from the collection.

Remove(HttpResponseHeader)

Removes the specified header from the collection.

Remove(String)

Removes the specified header from the collection.

Set(HttpRequestHeader, String)

Sets the specified header to the specified value.

Set(HttpResponseHeader, String)

Sets the specified header to the specified value.

Set(String, String)

Sets the specified header to the specified value.

ToByteArray()

Converts the WebHeaderCollection to a byte array.

ToString()

This method is obsolete.

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Copies the entire NameObjectCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.

(Inherited from NameObjectCollectionBase)
ICollection.IsSynchronized

Gets a value indicating whether access to the NameObjectCollectionBase object is synchronized (thread safe).

(Inherited from NameObjectCollectionBase)
ICollection.SyncRoot

Gets an object that can be used to synchronize access to the NameObjectCollectionBase object.

(Inherited from NameObjectCollectionBase)
IEnumerable.GetEnumerator()

Returns an enumerator that can iterate through the WebHeaderCollection instance.

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

Serializes this instance into the specified SerializationInfo object.

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to