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

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

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-

New line characters in header values must be followed by a white-space character.

Remarks

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.

Add(String, String)

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)

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-

New line characters in header values must be followed by a white-space character.

Remarks

The header value 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