Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HttpRequestHeaderCollection.TransferEncoding | transferEncoding property

Gets the HttpTransferCodingHeaderValueCollection of HttpTransferCodingHeaderValue objects that represent the value of a Transfer-Encoding HTTP header on an HTTP request.

Syntax


var transferEncoding = httpRequestHeaderCollection.transferEncoding;

Property value

Type: HttpTransferCodingHeaderValueCollection

The collection of HttpTransferCodingHeaderValue objects that represent the value of a Transfer-Encoding HTTP header on an HTTP request. An empty collection means that the header is absent.

Remarks

The only transfer encoding value supported by HttpClient is chunked, even though the HttpTransferCodingHeaderValueCollection of HttpTransferCodingHeaderValue objects supports setting other values.

There is no need to set the transfer encoding value manually to chunked if the HttpRequestMessage is sent as an IInputStream with no content-length specified or available using the GetInpuStreamAsync method on HttpClient or one of the ReadAsInputStreamAsync methods on the HTTP content classes.

The following sample code shows a method to set the Transfer-Encoding header on an HttpRequestMessage object using the TransferEncoding property on the HttpRequestHeaderCollection object.


    void DemoTransferEncoding(HttpRequestMessage m) {
        var h = m.Headers;

        uiLog.Text += "\nTRANSFERENCODING HEADER\n";
        // Transfer-Encoding: chunked
        var okTryParseAdd = h.TransferEncoding.TryParseAdd("chunked");
        okTryParseAdd = h.TransferEncoding.TryParseAdd("mini; a=b; c=d; e=f");
        h.TransferEncoding.Add(new HttpTransferCodingHeaderValue("cab"));
        h.TransferEncoding.TryParseAdd("newtype, othernewtype");

        // TransferEncoding is a HttpTransferCodingHeaderValueCollection
        // A collection of HttpTransferCodingHeaderValue

        // HttpTransferCodingHeaderValue has three items:
        // Value (string); e.g. "compress"
        // Parameter (IList<HttpNameValueHeaderValue>)
        //

        foreach (var item in h.TransferEncoding) {
            // item has: Value (string), Parameter IList<HttpNameValueHeaderValue>
            var parameterString = "";
            foreach (var parameter in item.Parameters) {
                parameterString += string.Format("[{0}={1}] ", parameter.Name, parameter.Value);
            }
            if (parameterString == "") {
                parameterString = "(no parameters)";
            } 
            uiLog.Text += string.Format("Value: {0} Parameters: {1} ToString: {2}\n", item.Value, parameterString, item.ToString());
        }
        uiLog.Text += string.Format("TransferEncoding: ToString: {0}\n\n", h.TransferEncoding.ToString());
    }


Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Web.Http.Headers
Windows::Web::Http::Headers [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Web.Http.Headers
Windows::Web::Http::Headers [C++]

Metadata

Windows.winmd

See also

HttpRequestHeaderCollection
HttpRequestMessage
HttpRequestMessage.Headers
HttpTransferCodingHeaderValue
HttpTransferCodingHeaderValueCollection

 

 

Show:
© 2015 Microsoft