WebHeaderCollection WebHeaderCollection WebHeaderCollection WebHeaderCollection Class

定義

包含與要求或回應關聯的通訊協定 (Protocol) 標頭。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)]
[System.Serializable]
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
繼承
屬性
實作

備註

類別通常是透過或WebResponse.HeadersWebRequest.Headers存取。 WebHeaderCollectionThe 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

  • 有望Expect

  • 主機Host

  • 如果-已修改-自起If-Modified-Since

  • RangeRange

  • 推薦者Referer

  • 傳輸-編碼Transfer-Encoding

  • 使用者代理程式User-Agent

  • Proxy-連線Proxy-Connection

建構函式

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

初始化 WebHeaderCollection 類別的新執行個體。Initializes a new instance of the WebHeaderCollection class.

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

初始化 WebHeaderCollection 類別的新執行個體,這個執行個體是來自 SerializationInfoStreamingContext 類別的指定執行個體。Initializes a new instance of the WebHeaderCollection class from the specified instances of the SerializationInfo and StreamingContext classes.

屬性

AllKeys AllKeys AllKeys AllKeys

取得集合中的所有標頭名稱 (索引鍵)。Gets all header names (keys) in the collection.

Count Count Count Count

取得集合中的標頭數目。Gets the number of headers in the collection.

ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized ICollection.IsSynchronized

取得值,表示是否要同步處理 (執行緒安全) 對 NameObjectCollectionBase 物件的存取。Gets a value indicating whether access to the NameObjectCollectionBase object is synchronized (thread safe).

(Inherited from NameObjectCollectionBase)
ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot ICollection.SyncRoot

取得可用來同步處理對 NameObjectCollectionBase 物件之存取的物件。Gets an object that can be used to synchronize access to the NameObjectCollectionBase object.

(Inherited from NameObjectCollectionBase)
IsReadOnly IsReadOnly IsReadOnly IsReadOnly

取得或設定值,表示 NameObjectCollectionBase 執行個體是否為唯讀。Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only.

(Inherited from NameObjectCollectionBase)
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[Int32] Item[Int32] Item[Int32] Item[Int32]

取得 NameValueCollection 的指定索引的項目。Gets the entry at the specified index of the NameValueCollection.

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

取得集合中的標頭名稱 (索引鍵) 集合。Gets the collection of header names (keys) in the collection.

方法

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

將指定 NameValueCollection 中的項目複製到目前的 NameValueCollectionCopies the entries in the specified NameValueCollection to the current NameValueCollection.

(Inherited from NameValueCollection)
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.

BaseAdd(String, Object) BaseAdd(String, Object) BaseAdd(String, Object) BaseAdd(String, Object)

將具有指定索引鍵和值的項目加入 NameObjectCollectionBase 執行個體。Adds an entry with the specified key and value into the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseClear() BaseClear() BaseClear() BaseClear()

將所有項目從 NameObjectCollectionBase 執行個體中移除。Removes all entries from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGet(Int32) BaseGet(Int32) BaseGet(Int32) BaseGet(Int32)

取得 NameObjectCollectionBase 執行個體指定索引處之項目的值。Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGet(String) BaseGet(String) BaseGet(String) BaseGet(String)

NameObjectCollectionBase 執行個體取得具有指定索引鍵之第一個項目的值。Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllKeys() BaseGetAllKeys() BaseGetAllKeys() BaseGetAllKeys()

傳回 String 陣列,其中包含 NameObjectCollectionBase 執行個體中的所有索引鍵。Returns a String array that contains all the keys in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllValues() BaseGetAllValues() BaseGetAllValues() BaseGetAllValues()

傳回 Object 陣列,其中包含 NameObjectCollectionBase 執行個體中的所有值。Returns an Object array that contains all the values in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetAllValues(Type) BaseGetAllValues(Type) BaseGetAllValues(Type) BaseGetAllValues(Type)

傳回指定類型的陣列,其中包含 NameObjectCollectionBase 執行個體中的所有值。Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseGetKey(Int32) BaseGetKey(Int32) BaseGetKey(Int32) BaseGetKey(Int32)

取得 NameObjectCollectionBase 執行個體指定索引處之項目的索引鍵。Gets the key of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseHasKeys() BaseHasKeys() BaseHasKeys() BaseHasKeys()

取得值,表示 NameObjectCollectionBase 執行個體是否包含其索引鍵不是 null 的項目。Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null.

(Inherited from NameObjectCollectionBase)
BaseRemove(String) BaseRemove(String) BaseRemove(String) BaseRemove(String)

將具有指定索引鍵的項目從 NameObjectCollectionBase 中移除。Removes the entries with the specified key from the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseRemoveAt(Int32) BaseRemoveAt(Int32) BaseRemoveAt(Int32) BaseRemoveAt(Int32)

移除 NameObjectCollectionBase 執行個體指定索引處的項目。Removes the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseSet(Int32, Object) BaseSet(Int32, Object) BaseSet(Int32, Object) BaseSet(Int32, Object)

設定 NameObjectCollectionBase 執行個體指定索引處之項目的值。Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.

(Inherited from NameObjectCollectionBase)
BaseSet(String, Object) BaseSet(String, Object) BaseSet(String, Object) 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() Clear() Clear() Clear()

移除集合中的所有標頭。Removes all headers from the collection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) 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) 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()

傳回可以逐一查看 WebHeaderCollection 執行個體的列舉值。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)

將序列化目標物件所需的資料填入 SerializationInfoPopulates a SerializationInfo with the data needed to serialize the target object.

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

取得目前執行個體的 TypeGets the Type of the current instance.

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

取得儲存於標頭集合的 index 位置之標頭值的陣列。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.

HasKeys() HasKeys() HasKeys() HasKeys()

取得值,指出 NameValueCollection 是否包含非 null 的索引鍵。Gets a value indicating whether the NameValueCollection contains keys that are not null.

(Inherited from NameValueCollection)
InvalidateCachedArrays() InvalidateCachedArrays() InvalidateCachedArrays() InvalidateCachedArrays()

將集合的快取陣列重設為 nullResets the cached arrays of the collection to null.

(Inherited from NameValueCollection)
IsRestricted(String) IsRestricted(String) IsRestricted(String) IsRestricted(String)

測試是否可為要求設定指定的 HTTP 標頭。Tests whether the specified HTTP header can be set for the request.

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

測試是否可以設定要求或回應之指定的 HTTP 標頭。Tests whether the specified HTTP header can be set for the request or the response.

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

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

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

實作 ISerializable 介面,並於還原序列化完成時引發還原序列化事件。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()

WebHeaderCollection 轉換成位元組陣列。Converts the WebHeaderCollection to a byte array.

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

這個方法已過時。This method is obsolete.

明確介面實作

ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) ICollection.CopyTo(Array, Int32) 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)
IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()
ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext) ISerializable.GetObjectData(SerializationInfo, StreamingContext)

將這個執行個體序列化為指定的 SerializationInfo 物件。Serializes this instance into the specified SerializationInfo object.

擴充方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於