HttpResponseHeaderCollection.TransferEncoding 属性

定义

获取 HttpTransferCodingHeaderValue 对象的 HttpTransferCodingHeaderValueCollection ,该对象表示 HTTP 响应中 Transfer-Encoding HTTP 标头的值。

public:
 property HttpTransferCodingHeaderValueCollection ^ TransferEncoding { HttpTransferCodingHeaderValueCollection ^ get(); };
HttpTransferCodingHeaderValueCollection TransferEncoding();
public HttpTransferCodingHeaderValueCollection TransferEncoding { get; }
var httpTransferCodingHeaderValueCollection = httpResponseHeaderCollection.transferEncoding;
Public ReadOnly Property TransferEncoding As HttpTransferCodingHeaderValueCollection

属性值

HttpTransferCodingHeaderValue 对象的集合,这些对象表示 HTTP 响应上的 Transfer-Encoding HTTP 标头的值。 空集合表示标头不存在。

注解

下面的示例代码演示了一种方法,该方法使用 HttpResponseHeaderCollection 对象的 TransferEncoding 属性获取和设置 HttpResponseMessage 对象上的 Transfer-Encoding 标头。

// HttpTransferCodingHeaderValueCollection
// HttpTransferCodingHeaderValue hasValue (string) and Parameters (IList<HttpNameValueHeaderValue>)
// IList<HttpNameValueHeaderValue>
// HttpNameValueHeaderValue
//
// This is the same type as on the Request TransferEncoding  value
void DemoTransferEncoding(HttpResponseMessage response) {
    var h = response.Headers;
    h.TransferEncoding.TryParseAdd("Basic");
    h.TransferEncoding.Add(new HttpTransferCodingHeaderValue("gzip"));

    var header = h.TransferEncoding;
    uiLog.Text += "\nTRANSFER ENCODING HEADER\n";
    foreach (var item in header) {
        // Parameters is an IList<HttpNameValueHeaderValue> of Name/Value strings
        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: {0}\n", header.ToString());
}

适用于

另请参阅