Share via


HttpResponseHeaderCollection.Connection Property

Definition

Gets the HttpConnectionOptionHeaderValueCollection of HttpConnectionOptionHeaderValue objects that represent the value of a Connection HTTP header on an HTTP response.

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

Property Value

The collection of HttpConnectionOptionHeaderValue objects that represent the value of a Connection HTTP header. An empty collection means that the header is absent.

Remarks

The following sample code shows a method to get and set the Connection header on an HttpResponseMessage object using the Connection property on the HttpResponseHeaderCollection object.

// 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());
    }

Applies to

See also