WebHeaderCollection 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
包含与请求或响应关联的协议标头。
public ref class WebHeaderCollection sealed : System::Collections::IEnumerablepublic ref class WebHeaderCollection : System::Collections::Specialized::NameValueCollection, System::Runtime::Serialization::ISerializablepublic ref class WebHeaderCollection : System::Collections::Specialized::NameValueCollectionpublic sealed class WebHeaderCollection : System.Collections.IEnumerablepublic 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.ISerializablepublic class WebHeaderCollection : System.Collections.Specialized.NameValueCollectiontype WebHeaderCollection = class
    interface IEnumerabletype WebHeaderCollection = class
    inherit NameValueCollection
    interface IEnumerable
    interface ISerializable[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type WebHeaderCollection = class
    inherit NameValueCollection
    interface ISerializabletype WebHeaderCollection = class
    inherit NameValueCollection
    interface ISerializablePublic NotInheritable Class WebHeaderCollection
Implements IEnumerablePublic Class WebHeaderCollection
Inherits NameValueCollection
Implements ISerializablePublic Class WebHeaderCollection
Inherits NameValueCollection- 继承
- 
				WebHeaderCollection
- 继承
- 属性
- 实现
注解
类 WebHeaderCollection 通常通过 WebRequest.Headers 或 WebResponse.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) | 
				已过时.
			 从 WebHeaderCollection 和 SerializationInfo 类的指定实例初始化 StreamingContext 类的新实例。 | 
属性
| AllKeys | 获取集合中的所有标头名(关键字)。 | 
| Count | 获取集合中的标头数。 | 
| IsReadOnly | 获取或设置一个值,通过该值指示 NameObjectCollectionBase 实例是否为只读的。(继承自 NameObjectCollectionBase) | 
| Item[HttpRequestHeader] | 获取或设置指定的请求标头。 | 
| Item[HttpResponseHeader] | 获取或设置指定的响应标头。 | 
| Item[Int32] | 获取 NameValueCollection 中指定索引处的项。(继承自 NameValueCollection) | 
| Item[String] | 包含与请求或响应关联的协议标头。 | 
| Item[String] | 获取或设置 NameValueCollection 中具有指定键的项。(继承自 NameValueCollection) | 
| Keys | 获取集合中的标头名(关键字)的集合。 | 
方法
显式接口实现
| 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。 |