共用方式為


HttpResponseHeaderCollection.Connection 屬性

定義

取得HttpConnectionOptionHeaderValueCollection 的 HttpConnectionOptionHeaderValue物件,這些物件代表 HTTP 回應上Connection HTTP 標頭的值。

public:
 property HttpConnectionOptionHeaderValueCollection ^ Connection { HttpConnectionOptionHeaderValueCollection ^ get(); };
HttpConnectionOptionHeaderValueCollection Connection();
public HttpConnectionOptionHeaderValueCollection Connection { get; }
var httpConnectionOptionHeaderValueCollection = httpResponseHeaderCollection.connection;
Public ReadOnly Property Connection As HttpConnectionOptionHeaderValueCollection

屬性值

HttpConnectionOptionHeaderValue物件的集合,代表Connection HTTP 標頭的值。 空集合表示標頭不存在。

備註

下列範例程式碼示範在HttpResponseMessage物件上使用HttpResponseHeaderCollection物件上的 Connection 屬性取得和設定Connection 標頭的方法

// Connection:keep-alive
// HttpConnectionOptionHeaderValueCollection, a collection of
// HttpConnectionOptionHeaderValue which just has a Token (string)
// 
// This is the same type as on the request
    void DemoConnection(HttpResponseMessage response) {
        var h = response.Headers;
        h.Connection.TryParseAdd("close");
        h.Connection.TryParseAdd("some,values");
        h.Connection.Add(new HttpConnectionOptionHeaderValue("last"));

        var header = h.Connection;
        uiLog.Text += "\nCONNECTION HEADER\n";
        foreach (var item in header) {
            uiLog.Text += String.Format("Token: {0}  ToString: {1}\n", item.Token, item.ToString());
        }
        uiLog.Text += String.Format("Connection: {0}\n", header.ToString());
    }

適用於

另請參閱