Читати англійською Редагувати

Поділитися через


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.

C#
public void Add(string name, System.Collections.Generic.IEnumerable<string> values);
C#
public void Add(string name, System.Collections.Generic.IEnumerable<string?> values);

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

.NET 10 та інші версії
Продукт Версії
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Add(String, String)

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

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

C#
public void Add(string name, string value);
C#
public void Add(string name, string? value);

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

.NET 10 та інші версії
Продукт Версії
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0