Skip to content

Latest commit

 

History

History
67 lines (48 loc) · 3.5 KB

httprequestheadercollection_transferencoding.md

File metadata and controls

67 lines (48 loc) · 3.5 KB
-api-id -api-type
P:Windows.Web.Http.Headers.HttpRequestHeaderCollection.TransferEncoding
winrt property

Windows.Web.Http.Headers.HttpRequestHeaderCollection.TransferEncoding

-description

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

-property-value

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 with no content-length specified or available using the method on HttpClient or one of the 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); for example, "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());
    }

-examples

-see-also

HttpRequestMessage, HttpRequestMessage.Headers, HttpTransferCodingHeaderValue, HttpTransferCodingHeaderValueCollection