Επεξεργασία

Κοινή χρήση μέσω


HttpHeaders.Add Method

Definition

Inserts a new header and its values into the HttpHeaders collection.

Overloads

Add(String, IEnumerable<String>)

Adds the specified header and its values into the HttpHeaders collection.

Add(String, String)

Adds the specified header and its value into the HttpHeaders collection.

Add(String, IEnumerable<String>)

Source:
HttpHeaders.cs
Source:
HttpHeaders.cs
Source:
HttpHeaders.cs

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

Parameters

name
String

The header to add to the collection.

values
IEnumerable<String>

A list of header values to add to the collection.

Exceptions

The name cannot be null or empty.

The values cannot be null or empty.

Misused header name. 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-

The header value format is invalid for this header name, or the header does not support multiple values.

Remarks

Header names are enforced to be valid HTTP tokens, where a token is defined as any set of ASCII letters, digits, or symbols from the "!#$%&'*+-.^_`|~" set, matching RFC9110's definition. Non-ASCII characters are not allowed in a header name.

The header values will be parsed and validated.

If the specified header does not exist, the Add method inserts a new header into the list of header name/value pairs.

If the specified header is already present, values are added to the comma-separated list of values associated with the header.

Applies to

Add(String, String)

Source:
HttpHeaders.cs
Source:
HttpHeaders.cs
Source:
HttpHeaders.cs

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);
public void Add (string name, string? value);
member this.Add : string * string -> unit
Public Sub Add (name As String, value As String)

Parameters

name
String

The header to add to the collection.

value
String

The content of the header.

Exceptions

The name cannot be null or empty.

Misused header name. 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-

The header value format is invalid for this header name, or the header does not support multiple values.

Remarks

Header names are enforced to be valid HTTP tokens, where a token is defined as any set of ASCII letters, digits, or symbols from the "!#$%&'*+-.^_`|~" set, matching RFC9110's definition. Non-ASCII characters are not allowed in a header name.

The header values will be parsed and validated.

If the specified header does not exist, the Add method inserts a new header into the list of header name/value pairs.

If the specified header is already present, value is added to the comma-separated list of values associated with the header.

Applies to