HttpHeaders.Add 方法

定義

將新標頭及其值插入至 HttpHeaders 集合。Inserts a new header and its values into the HttpHeaders collection.

多載

Add(String, IEnumerable<String>)

將指定的標頭及其值加入至 HttpHeaders 集合中。Adds the specified header and its values into the HttpHeaders collection.

Add(String, String)

將指定的標頭及其值加入至 HttpHeaders 集合中。Adds the specified header and its value into the HttpHeaders collection.

Add(String, IEnumerable<String>)

將指定的標頭及其值加入至 HttpHeaders 集合中。Adds the specified header and its values into the HttpHeaders collection.

public:
 void Add(System::String ^ name, System::Collections::Generic::IEnumerable<System::String ^> ^ values);
public void Add (string name, System.Collections.Generic.IEnumerable<string> values);
member this.Add : string * seq<string> -> unit
Public Sub Add (name As String, values As IEnumerable(Of String))

參數

name
String

要加入至集合的標頭。The header to add to the collection.

values
IEnumerable<String>

要加入至集合的標頭值清單。A list of header values to add to the collection.

例外狀況

名稱不可為 Null 或空白。The name cannot be null or empty.

值不可為 Null 或空白。The values cannot be null or empty.

標頭名稱使用錯誤。Misused header name. 請確認要求標頭搭配 HttpRequestMessage 物件使用;回應標頭搭配 HttpResponseMessage 物件使用;而內容標頭則搭配 HttpContent 物件使用。Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.

標頭名稱格式無效。The header name format is invalid.

-或--or-

標頭值中的新行字元後面必須接著空白字元。New line characters in header values must be followed by a white-space character.

備註

標頭values將會經過剖析和驗證。The header values will be parsed and validated.

如果指定的標頭不存在,則Add方法會將新的標頭插入標頭名稱/值組的清單中。If the specified header does not exist, the Add method inserts a new header into the list of header name/value pairs.

如果指定的標頭已存在, values則會加入至與標頭相關聯之值的逗號分隔清單中。If the specified header is already present, values are added to the comma-separated list of values associated with the header.

Add(String, String)

將指定的標頭及其值加入至 HttpHeaders 集合中。Adds the specified header and its value into the HttpHeaders collection.

public:
 void Add(System::String ^ name, System::String ^ value);
public void Add (string name, string value);
member this.Add : string * string -> unit
Public Sub Add (name As String, value As String)

參數

name
String

要加入至集合的標頭。The header to add to the collection.

value
String

標頭的內容。The content of the header.

例外狀況

名稱不可為 Null 或空白。The name cannot be null or empty.

標頭名稱使用錯誤。Misused header name. 請確認要求標頭搭配 HttpRequestMessage 物件使用;回應標頭搭配 HttpResponseMessage 物件使用;而內容標頭則搭配 HttpContent 物件使用。Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.

標頭名稱格式無效。The header name format is invalid.

-或--or-

標頭值中的新行字元後面必須接著空白字元。New line characters in header values must be followed by a white-space character.

備註

標頭value將會經過剖析和驗證。The header value will be parsed and validated.

如果指定的標頭不存在,則Add方法會將新的標頭插入標頭名稱/值組的清單中。If the specified header does not exist, the Add method inserts a new header into the list of header name/value pairs.

如果指定的標頭已存在, value則會新增至與標頭相關聯之值的逗號分隔清單。If the specified header is already present, value is added to the comma-separated list of values associated with the header.

適用於