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

通常 WebHeaderCollection 类通过 WebRequest.HeadersWebResponse.Headers访问。The WebHeaderCollection class is generally accessed through WebRequest.Headers or WebResponse.Headers. 某些常用标头被视为受限制,并由 API 直接公开(如 Content-Type)或受系统保护,无法更改。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-LengthContent-Length

  • Content-TypeContent-Type

  • 日期Date

  • ExpectExpect

  • HostHost

  • If-Modified-SinceIf-Modified-Since

  • 范围Range

  • RefererReferer

  • Transfer-EncodingTransfer-Encoding

  • User-AgentUser-Agent

  • 代理-连接Proxy-Connection

Constructors

WebHeaderCollection()

初始化 WebHeaderCollection 类的新实例。Initializes a new instance of the WebHeaderCollection class.

Properties

AllKeys

获取集合中的所有标头名(关键字)。Gets all header names (keys) in the collection.

Count

获取集合中的标头数。Gets the number of headers in the collection.

IsReadOnly

获取或设置一个值,通过该值指示 NameObjectCollectionBase 实例是否为只读的。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]

获取指定的 NameValueCollection 索引处的条目。Gets the entry at the specified index of the NameValueCollection.

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

获取或设置 NameValueCollection 中具有指定键的项。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)

将指定 NameValueCollection 中的项复制到当前 NameValueCollectionCopies the entries in the specified NameValueCollection to the current NameValueCollection.

(Inherited from NameValueCollection)
Add(String)

将指定的标头插入集合中。Inserts the specified header into the collection.

Add(String, String)

将具有指定名称和值的标头插入到集合中。Inserts a header with the specified name and value into the collection.

BaseAdd(String, Object)

将具有指定键和值的项添加到 NameObjectCollectionBase 实例中。Adds an entry with the specified key and value into the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseClear()

移除 NameObjectCollectionBase 实例中的所有项。Removes all entries from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGet(Int32)

获取 NameObjectCollectionBase 实例的指定索引处的项值。Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGet(String)

获取 NameObjectCollectionBase 实例中第一个具有指定键的项值。Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllKeys()

返回 String 数组,该数组包含 NameObjectCollectionBase 实例中的所有键。Returns a String array that contains all the keys in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllValues()

返回 Object 数组,该数组包含 NameObjectCollectionBase 实例中的所有值。Returns an Object array that contains all the values in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllValues(Type)

返回指定类型的数组,该数组包含 NameObjectCollectionBase 实例中的所有值。Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetKey(Int32)

获取 NameObjectCollectionBase 实例的指定索引处的项键。Gets the key of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseHasKeys()

获取一个值,通过该值指示 NameObjectCollectionBase 实例是否包含键不为 null 的项。Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null.

(Inherited from NameObjectCollectionBase)
BaseRemove(String)

移除 NameObjectCollectionBase 实例中具有指定键的项。Removes the entries with the specified key from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseRemoveAt(Int32)

移除 NameObjectCollectionBase 实例的指定索引处的项。Removes the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseSet(Int32, Object)

设置 NameObjectCollectionBase 实例的指定索引处的项值。Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseSet(String, Object)

NameObjectCollectionBase 实例中第一个具有指定键的项设置值(如果有这样的项);否则将具有指定键和值的项添加到 NameObjectCollectionBase 实例中。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()

使缓存数组无效,并将所有项从 NameValueCollection 中移除。Invalidates the cached arrays and removes all entries from the NameValueCollection.

(Inherited from NameValueCollection)
CopyTo(Array, Int32)

从目标数组的指定索引处开始将整个 NameValueCollection 复制到兼容的一维 ArrayCopies 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()

返回可遍历 WebHeaderCollection 实例的枚举器。Returns an enumerator that can iterate through the WebHeaderCollection instance.

GetEnumerator()

返回循环访问 NameObjectCollectionBase 的枚举器。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)

使用序列化目标对象所需的数据填充 SerializationInfoPopulates a SerializationInfo with the data needed to serialize the target object.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
GetValues(Int32)

获取存储在标头集合的 index 位置中的标头值数组。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()

获取一个值,该值指示 NameValueCollection 是否包含非 null 的键。Gets a value indicating whether the NameValueCollection contains keys that are not null.

(Inherited from NameValueCollection)
InvalidateCachedArrays()

将集合的缓存数组重置为 nullResets the cached arrays of the collection to null.

(Inherited from NameValueCollection)
IsRestricted(String)

测试是否能够为请求设置指定的 HTTP 标头。Tests whether the specified HTTP header can be set for the request.

IsRestricted(String, Boolean)

测试是否能够为请求或响应设置指定的 HTTP 标头。Tests whether the specified HTTP header can be set for the request or the response.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialization(Object)

实现 ISerializable 接口,并在完成反序列化之后引发反序列化事件。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()

WebHeaderCollection 转换为字节数组。Converts the WebHeaderCollection to a byte array.

ToString()

此方法已过时。This method is obsolete.

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

从目标数组的指定索引处开始将整个 NameObjectCollectionBase 复制到兼容的一维 ArrayCopies the entire NameObjectCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.

(Inherited from NameObjectCollectionBase)
ICollection.IsSynchronized

获取一个值,该值指示对 NameObjectCollectionBase 对象的访问是否同步(线程安全)。Gets a value indicating whether access to the NameObjectCollectionBase object is synchronized (thread safe).

(Inherited from NameObjectCollectionBase)
ICollection.SyncRoot

获取一个对象,该对象可用于同步对 NameObjectCollectionBase 对象的访问。Gets an object that can be used to synchronize access to the NameObjectCollectionBase object.

(Inherited from NameObjectCollectionBase)
IEnumerable.GetEnumerator()
ISerializable.GetObjectData(SerializationInfo, StreamingContext)

将此实例序列化到指定的 SerializationInfo 对象中。Serializes this instance into the specified SerializationInfo object.

Extension Methods

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

Applies to