Represents the Transfer-Encoding HTTP header. This class is part of the System.Net.Http.Headers namespace.
The TransferCodings class provides a strongly-typed representation of the Transfer-Encoding header value used in HTTP requests and responses. This header specifies the transfer encoding methods that are applied to the message. Common transfer codings include chunked. This class is often used in conjunction with the HttpRequestHeaders and HttpResponseHeaders collections.
The Transfer-Encoding header is a hop-by-hop header that is used to indicate which transfer-mechanism has been applied to the message body. It is an optional header. When present, it must be one or more of the following:
chunked: Indicates that the message body is transferred in a series of chunks.compress: Indicates that the message body has been compressed using the compress algorithm.deflate: Indicates that the message body has been compressed using the deflate algorithm.gzip: Indicates that the message body has been compressed using the gzip algorithm.The TransferCodings class provides methods to parse and serialize the Transfer-Encoding header value.
This class does not expose any public fields.
This class does not expose any public properties.
The TransferCodings class typically exposes static methods for parsing and formatting the Transfer-Encoding header value. For instance, methods to get or set the TransferCodings object from an HttpHeaders collection.
public static TransferCodingHeaderValue Parse(string input);
Parses a string representation of a Transfer-Encoding header value and returns an instance of TransferCodingHeaderValue.
public static bool TryParse(string input, out TransferCodingHeaderValue parsedValue);
Attempts to parse a string representation of a Transfer-Encoding header value and returns a value that indicates whether the operation succeeded.
While TransferCodings itself is often treated as a value type or a container for parsing/formatting, individual transfer codings might be represented by other classes like TransferCodingHeaderValue, which would have instance methods.
public override string ToString();
Returns a string representation of the current TransferCodings object.
using System;
using System.Net.Http.Headers;
// ...
string headerValue = "chunked, gzip";
TransferCodingHeaderValue transferCoding = TransferCodingHeaderValue.Parse(headerValue);
Console.WriteLine($"Parsed Transfer-Encoding: {transferCoding}");
// Output: Parsed Transfer-Encoding: chunked, gzip
using System;
using System.Net.Http;
using System.Net.Http.Headers;
// ...
var request = new HttpRequestMessage(HttpMethod.Get, "http://example.com");
// Add chunked encoding
request.Headers.TransferEncoding.Add(new TransferCodingHeaderValue("chunked"));
// Add gzip encoding (if supported by the client/server negotiation)
request.Headers.TransferEncoding.Add(new TransferCodingHeaderValue("gzip"));
Console.WriteLine($"Request Transfer-Encoding: {request.Headers.TransferEncoding}");
// Output: Request Transfer-Encoding: chunked, gzip