WebHeaderCollection 类

定义

包含与请求或响应关联的协议标头。

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
继承
WebHeaderCollection
继承
属性
实现

注解

WebHeaderCollection 通常通过 WebRequest.HeadersWebResponse.Headers进行访问。

在.NET Framework,一些常见标头被视为受限,要么直接由 API ((如Content-Type) )公开,要么由系统保护,并且无法更改。 这 不适用于 . NET Core 和 .NET 5+,其中没有任何标头受到限制。

受限制的标头包括:

  • Accept

  • 连接

  • Content-Length

  • Content-Type

  • Date

  • Expect

  • 主机

  • If-Modified-Since

  • 范围

  • Referer

  • Transfer-Encoding

  • User-Agent

  • Proxy-Connection

构造函数

WebHeaderCollection()

初始化 WebHeaderCollection 类的新实例。

WebHeaderCollection(SerializationInfo, StreamingContext)

WebHeaderCollectionSerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。

属性

AllKeys

获取集合中的所有标头名(关键字)。

Count

获取集合中的标头数。

IsReadOnly

获取或设置一个值,通过该值指示 NameObjectCollectionBase 实例是否为只读的。

(继承自 NameObjectCollectionBase)
Item[HttpRequestHeader]

获取或设置指定的请求标头。

Item[HttpResponseHeader]

获取或设置指定的响应标头。

Item[Int32]

获取 NameValueCollection 中指定索引处的项。

(继承自 NameValueCollection)
Item[String]

包含与请求或响应关联的协议标头。

Item[String]

获取或设置 NameValueCollection 中具有指定键的项。

(继承自 NameValueCollection)
Keys

获取集合中的标头名(关键字)的集合。

方法

Add(HttpRequestHeader, String)

将包含指定值的指定标头插入到集合中。

Add(HttpResponseHeader, String)

将包含指定值的指定标头插入到集合中。

Add(NameValueCollection)

将指定 NameValueCollection 中的项复制到当前 NameValueCollection

(继承自 NameValueCollection)
Add(String)

将指定的标头插入集合中。

Add(String, String)

将具有指定名称和值的标头插入到集合中。

AddWithoutValidate(String, String)

将标头插入到集合中,不检查此标头是否在受限制的标头列表上。

BaseAdd(String, Object)

将具有指定键和值的项添加到 NameObjectCollectionBase 实例中。

(继承自 NameObjectCollectionBase)
BaseClear()

移除 NameObjectCollectionBase 实例中的所有项。

(继承自 NameObjectCollectionBase)
BaseGet(Int32)

获取 NameObjectCollectionBase 实例的指定索引处的项值。

(继承自 NameObjectCollectionBase)
BaseGet(String)

获取 NameObjectCollectionBase 实例中第一个具有指定键的项值。

(继承自 NameObjectCollectionBase)
BaseGetAllKeys()

返回 String 数组,该数组包含 NameObjectCollectionBase 实例中的所有键。

(继承自 NameObjectCollectionBase)
BaseGetAllValues()

返回 Object 数组,该数组包含 NameObjectCollectionBase 实例中的所有值。

(继承自 NameObjectCollectionBase)
BaseGetAllValues(Type)

返回指定类型的数组,该数组包含 NameObjectCollectionBase 实例中的所有值。

(继承自 NameObjectCollectionBase)
BaseGetKey(Int32)

获取 NameObjectCollectionBase 实例的指定索引处的项键。

(继承自 NameObjectCollectionBase)
BaseHasKeys()

获取一个值,通过该值指示 NameObjectCollectionBase 实例是否包含键不为 null 的项。

(继承自 NameObjectCollectionBase)
BaseRemove(String)

移除 NameObjectCollectionBase 实例中具有指定键的项。

(继承自 NameObjectCollectionBase)
BaseRemoveAt(Int32)

移除 NameObjectCollectionBase 实例的指定索引处的项。

(继承自 NameObjectCollectionBase)
BaseSet(Int32, Object)

设置 NameObjectCollectionBase 实例的指定索引处的项值。

(继承自 NameObjectCollectionBase)
BaseSet(String, Object)

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

(继承自 NameObjectCollectionBase)
Clear()

从集合中移除所有标头。

Clear()

使缓存数组无效,并将所有项从 NameValueCollection 中移除。

(继承自 NameValueCollection)
CopyTo(Array, Int32)

从目标数组的指定索引处开始将整个 NameValueCollection 复制到兼容的一维 Array

(继承自 NameValueCollection)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Get(Int32)

获取集合中特定标头的值,该值由索引指定到集合中。

Get(String)

获取集合中特定标头的值,该值由标头名指定。

GetEnumerator()

返回可循环访问 WebHeaderCollection 实例的枚举器。

GetEnumerator()

返回循环访问 NameObjectCollectionBase 的枚举数。

(继承自 NameObjectCollectionBase)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetKey(Int32)

获取集合中位于指定位置的标头名。

GetObjectData(SerializationInfo, StreamingContext)

使用将目标对象序列化所需的数据填充 SerializationInfo

GetType()

获取当前实例的 Type

(继承自 Object)
GetValues(Int32)

获取存储在标头集合的 index 位置中的标头值数组。

GetValues(String)

获取标头中存储的标头值数组。

HasKeys()

获取一个值,该值指示 NameValueCollection 是否包含非 null 的键。

(继承自 NameValueCollection)
InvalidateCachedArrays()

将集合的缓存数组重置为 null

(继承自 NameValueCollection)
IsRestricted(String)

测试是否能够为请求设置指定的 HTTP 标头。

IsRestricted(String, Boolean)

测试是否能够为请求或响应设置指定的 HTTP 标头。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
OnDeserialization(Object)

实现 ISerializable 接口,并在完成反序列化之后引发反序列化事件。

Remove(HttpRequestHeader)

从集合中移除指定的标头。

Remove(HttpResponseHeader)

从集合中移除指定的标头。

Remove(String)

从集合中移除指定的标头。

Set(HttpRequestHeader, String)

将指定的标头设置为指定的值。

Set(HttpResponseHeader, String)

将指定的标头设置为指定的值。

Set(String, String)

将指定的标头设置为指定的值。

ToByteArray()

WebHeaderCollection 转换为字节数组。

ToString()

此方法已过时。

显式接口实现

ICollection.CopyTo(Array, Int32)

从目标数组的指定索引处开始将整个 NameObjectCollectionBase 复制到兼容的一维 Array

(继承自 NameObjectCollectionBase)
ICollection.IsSynchronized

获取一个值,该值指示对 NameObjectCollectionBase 对象的访问是否同步(线程安全)。

(继承自 NameObjectCollectionBase)
ICollection.SyncRoot

获取一个对象,该对象可用于同步对 NameObjectCollectionBase 对象的访问。

(继承自 NameObjectCollectionBase)
IEnumerable.GetEnumerator()

返回可循环访问 WebHeaderCollection 实例的枚举器。

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

将此实例序列化到指定的 SerializationInfo 对象中。

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

适用于