HttpResponseHeaderCollection HttpResponseHeaderCollection HttpResponseHeaderCollection HttpResponseHeaderCollection Class

Provides a collection of the HTTP headers associated with an HTTP response.

Syntax

Declaration

public sealed class HttpResponseHeaderCollectionpublic sealed class HttpResponseHeaderCollectionPublic NotInheritable Class HttpResponseHeaderCollectionpublic sealed class HttpResponseHeaderCollection

Remarks

The HttpResponseHeaderCollection is a collection of the HTTP headers associated with an HTTP response to an HTTP request message. The HttpResponseHeaderCollection object can be used to get or set the specific headers on the HTTP response. Most of the properties on the HttpResponseHeaderCollection object provide access for the value of a specific HTTP header.

The Headers property on HttpResponseMessage returns an HttpResponseHeaderCollection object. This is how an HttpResponseHeaderCollection is constructed.

Enumerating the collection in C# or Microsoft Visual Basic

You can iterate through an HttpResponseHeaderCollection object in C# or Microsoft Visual Basic. In many cases, such as using foreach syntax, the compiler does this casting for you and you won't need to cast to IEnumerable explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast the collection object to IEnumerable<T> with a KeyValuePair of String and String as the constraint.

Examples

The following sample code shows a method to get and set response headers on an HttpResponseMessage object using the properties on the HttpResponseHeaderCollection object. The Windows.Web.Http.Headers namespace has a number of strongly-typed header collection and value classes for specific HTTP headers that can be used to get and set headers with validation.


using System;
using System.Collections.Generic;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

        void DemonstrateResponseHeaders() {

            DemonstrateHeaderResponseAge();
            DemonstrateHeaderResponseAllow();
            DemonstrateHeaderResponseCacheControl();
            DemonstrateHeaderResponseDate();
            DemonstrateHeaderResponseLocation();
            DemonstrateHeaderResponseProxyAuthenticate();

        }


        public void DemonstrateHeaderResponseAge()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            DateTimeOffset value = DateTimeOffset.UtcNow;
            response.Headers.Age = new TimeSpan(1, 35, 55); // 1 hour, 35 minutes, 55 seconds.

            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Age value in minutes: {0}", response.Headers.Age.Value.TotalMinutes);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Age ToString() results: {0}", response.Headers.Age.ToString());
        }


        public void DemonstrateHeaderResponseAllow()
        {
            var response = new HttpResponseMessage();

            // Set the header with a string
            response.Headers.Allow.TryParseAdd ("GET");

            // Set the header with a strong type
            response.Headers.Allow.Add(HttpMethod.Patch);

            // Get the strong type out
            foreach (var value in response.Headers.Allow)
            {
                System.Diagnostics.Debug.WriteLine("Allow value: {0}", value.Method);
            }

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Allow ToString() results: {0}", response.Headers.Allow.ToString());
        }

        public void DemonstrateHeaderResponseCacheControl()
        {
            var response = new HttpResponseMessage();

            // Set the header with a string
            response.Headers.CacheControl.TryParseAdd("public");

            // Set the header with a strong type
            response.Headers.CacheControl.Add(new HttpNameValueHeaderValue("max-age", "30"));

            // Get the strong type out
            foreach (var value in response.Headers.CacheControl)
            {
                System.Diagnostics.Debug.WriteLine("CacheControl {0}={1}", value.Name, value.Value);
            }

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The CacheControl ToString() results: {0}", response.Headers.CacheControl.ToString());
        }

        public void DemonstrateHeaderResponseDate()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            response.Headers.Date = DateTimeOffset.UtcNow;

            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Date value in ticks: {0}", response.Headers.Date.Value.Ticks);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Date ToString() results: {0}", response.Headers.Date.ToString());
        }

        public void DemonstrateHeaderResponseLocation()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            response.Headers.Location = new Uri("http://example.com/");

            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Location absolute uri: {0}", response.Headers.Location.AbsoluteUri);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Location ToString() results: {0}", response.Headers.Location.ToString());
        }

        public void DemonstrateHeaderResponseProxyAuthenticate()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            response.Headers.ProxyAuthenticate.TryParseAdd("Basic");
            response.Headers.ProxyAuthenticate.Add(new HttpChallengeHeaderValue("authScheme", "authToken"));

            // Get the strong type out
            foreach (var value in response.Headers.ProxyAuthenticate)
            {
                System.Diagnostics.Debug.WriteLine("Proxy authenticate scheme and token: {0} {1}", value.Scheme, value.Token);
            }

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The ProxyAuthenticate ToString() results: {0}", response.Headers.ProxyAuthenticate.ToString());
        }

        public void DemonstrateHeaderResponseRetryAfter()
        {
            var response = new HttpResponseMessage();

            // Set the header with a strong type.
            HttpDateOrDeltaHeaderValue newvalue;
            bool parseOk = HttpDateOrDeltaHeaderValue.TryParse("", out newvalue);
            if (parseOk)
            {
                response.Headers.RetryAfter = newvalue;
            }

            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Date value in ticks: {0}", response.Headers.Date.Value.Ticks);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Date ToString() results: {0}", response.Headers.Date.ToString());
        }

Properties summary

Gets or sets the TimeSpan object that represents the value of an Age HTTP header on an HTTP response.

Gets the HttpMethodHeaderValueCollection of HttpMethod objects that represent the value of an Allow HTTP header on an HTTP response.

Gets the HttpCacheDirectiveHeaderValueCollection of objects that represent the value of a Cache-Control HTTP header on an HTTP response.

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

Gets or sets the DateTime object that represents the value of a Date HTTP header on an HTTP response.

Gets or sets the Uri that represents the value or a Location HTTP header on an HTTP response.

Gets the HttpChallengeHeaderValueCollection of HttpChallengeHeaderValue objects that represent the value of a Proxy-Authenticate HTTP header on an HTTP response.

Gets or sets the HttpDateOrDeltaHeaderValue object that represent the value of a Retry-After HTTP header on an HTTP response.

Gets the number of objects in the HttpResponseHeaderCollection.

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

Gets the HttpChallengeHeaderValueCollection of HttpChallengeHeaderValue objects that represent the value of a WWW-Authenticate HTTP header on an HTTP response.

Methods summary

Adds a new item to the end of the HttpResponseHeaderCollection.

Removes all objects from the collection.

Retrieves an iterator to the first item in the HttpResponseHeaderCollection.

Returns an immutable view of the HttpResponseHeaderCollection.

Determines whether the HttpResponseHeaderCollection contains the specified key.

Inserts or replaces an item in the HttpResponseHeaderCollection with the specified key and value.

Lookup an item in the HttpResponseHeaderCollection.

Removes an item with a given key from the HttpResponseHeaderCollection.

Returns a string that represents the current HttpResponseHeaderCollection object.

Try to append the specified item to the HttpResponseHeaderCollection without validation.

Properties

  • Age
    Age
    Age
    Age

    Gets or sets the TimeSpan object that represents the value of an Age HTTP header on an HTTP response.

    public IReference<TimeSpan> Age { get; set; }public IReference<TimeSpan> Age { get; set; }Public ReadWrite Property Age As IReference<TimeSpan>public IReference<TimeSpan> Age { get; set; }

    Property Value

    • The object that represents the value of an Age HTTP header on an HTTP response. A null value means that the header is absent.

    Remarks

    The Age property represents the value of he Age header on an HTTP response. The Age header is the age of the entity in the cache.

    When programming with .NET, this structure is hidden and developers should use the System.TimeSpan structure. The value can be null, because it's typed as TimeSpan? (a nullable TimeSpan).

    In JavaScript, this structure is accessed as a value, not as an object. For example, use var a = 10000, not var a = { duration: 10000 }.

    Note

    In JavaScript, this structure is treated as the number of millisecond intervals, not the number of 100-nanosecond intervals. Therefore, TimeSpan values can lose precision when being ported between languages.

    For more detailed information, see the TimeSpan interface.

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

        public void DemonstrateHeaderResponseAge() {
            var response = new HttpResponseMessage();
    
            // Set the header with a strong type.
            DateTimeOffset value = DateTimeOffset.UtcNow;
            response.Headers.Age = new TimeSpan(1, 35, 55); // 1 hour, 35 minutes, 55 seconds.
    
            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Age value in minutes: {0}", response.Headers.Age.Value.TotalMinutes);
    
            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Age ToString() results: {0}", response.Headers.Age.ToString());
        }
    
  • Allow
    Allow
    Allow
    Allow

    Gets the HttpMethodHeaderValueCollection of HttpMethod objects that represent the value of an Allow HTTP header on an HTTP response.

    public HttpMethodHeaderValueCollection Allow { get; }public HttpMethodHeaderValueCollection Allow { get; }Public ReadOnly Property Allow As HttpMethodHeaderValueCollectionpublic HttpMethodHeaderValueCollection Allow { get; }

    Property Value

    Remarks

    The Allow property represents the value of an Allow HTTP header on an HTTP response. The Allow header is a list of HTTP methods (GET, PUT, and POST, for example) allowed by the HTTP server.

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

        public void DemonstrateHeaderResponseAllow() {
            var response = new HttpResponseMessage();
    
            // Set the header with a string
            response.Headers.Allow.TryParseAdd ("GET");
    
            // Set the header with a strong type
            response.Headers.Allow.Add(HttpMethod.Patch);
    
            // Get the strong type out
            foreach (var value in response.Headers.Allow) {
                System.Diagnostics.Debug.WriteLine("Allow value: {0}", value.Method);
            }
    
            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Allow ToString() results: {0}", response.Headers.Allow.ToString());
        }
    
  • CacheControl
    CacheControl
    CacheControl
    CacheControl

    Gets the HttpCacheDirectiveHeaderValueCollection of objects that represent the value of a Cache-Control HTTP header on an HTTP response.

    public HttpCacheDirectiveHeaderValueCollection CacheControl { get; }public HttpCacheDirectiveHeaderValueCollection CacheControl { get; }Public ReadOnly Property CacheControl As HttpCacheDirectiveHeaderValueCollectionpublic HttpCacheDirectiveHeaderValueCollection CacheControl { get; }

    Property Value

    Remarks

    The CacheControl property represents the value of a Cache-Control HTTP header on an HTTP response.

    Some of the objects in the HttpCacheDirectiveHeaderValueCollection for the Cache-Control header use the TimeSpan structure. When programming with .NET, this structure is hidden and developers should use the System.TimeSpan structure. The value can be null, because it's typed as TimeSpan? (a nullable TimeSpan).

    In JavaScript, this structure is accessed as a value, not as an object. For example, use var a = 10000, not var a = { duration: 10000 }.

    Note

    In JavaScript, this structure is treated as the number of millisecond intervals, not the number of 100-nanosecond intervals.

    For more detailed information, see the TimeSpan interface.

  • Connection
    Connection
    Connection
    Connection

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

    public HttpConnectionOptionHeaderValueCollection Connection { get; }public HttpConnectionOptionHeaderValueCollection Connection { get; }Public ReadOnly Property Connection As HttpConnectionOptionHeaderValueCollectionpublic HttpConnectionOptionHeaderValueCollection Connection { get; }

    Property Value

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

    Gets or sets the DateTime object that represents the value of a Date HTTP header on an HTTP response.

    public IReference<DateTime> Date { get; set; }public IReference<DateTime> Date { get; set; }Public ReadWrite Property Date As IReference<DateTime>public IReference<DateTime> Date { get; set; }

    Property Value

    • The object that represents the value of a Date HTTP header on an HTTP request. A null value means that the header is absent.

    Remarks

    The Date property represents the value of a Date HTTP header on an HTTP response. The Date header is the date and time the message was sent.

    Javascript and .NET languages do not use the DateTime object directly. In Javascript a DateTime is projected as a object, and in .NET it is projected as a System.DateTimeOffset. Each language transparently handles the conversion to the granularity and date ranges for the respective language.

    In C++, a value has the same granularity as a and supports the date ranges required by Javascript and .NET.

    For more detailed information, see the DateTime structure.

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

        public void DemonstrateHeaderResponseDate() {
            var response = new HttpResponseMessage();
    
            // Set the header with a strong type.
            response.Headers.Date = DateTimeOffset.UtcNow;
    
            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Date value in ticks: {0}", response.Headers.Date.Value.Ticks);
    
            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Date ToString() results: {0}", response.Headers.Date.ToString());
        }
    
  • Location
    Location
    Location
    Location

    Gets or sets the Uri that represents the value or a Location HTTP header on an HTTP response.

    public Uri Location { get; set; }public Uri Location { get; set; }Public ReadWrite Property Location As Uripublic Uri Location { get; set; }

    Property Value

    • The object that represents the value of a Location HTTP header on an HTTP response. A null value means that the header is absent.

    Remarks

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

        public void DemonstrateHeaderResponseLocation() {
            var response = new HttpResponseMessage();
    
            // Set the header with a strong type.
            response.Headers.Location = new Uri("http://example.com/");
    
            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("Location absolute uri: {0}", response.Headers.Location.AbsoluteUri);
    
            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Location ToString() results: {0}", response.Headers.Location.ToString());
        }
    
  • ProxyAuthenticate
    ProxyAuthenticate
    ProxyAuthenticate
    ProxyAuthenticate

    Gets the HttpChallengeHeaderValueCollection of HttpChallengeHeaderValue objects that represent the value of a Proxy-Authenticate HTTP header on an HTTP response.

    public HttpChallengeHeaderValueCollection ProxyAuthenticate { get; }public HttpChallengeHeaderValueCollection ProxyAuthenticate { get; }Public ReadOnly Property ProxyAuthenticate As HttpChallengeHeaderValueCollectionpublic HttpChallengeHeaderValueCollection ProxyAuthenticate { get; }

    Property Value

    Remarks

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

    // Proxy-Authenticate: Basic
    // HttpChallengeHeaderValueCollection
    // HttpChallengeHeaderValue has Scheme and Token (both strings) + Parameters
    // Parameters is an IList<HttpNameValueHeaderValue>
    // HttpNameValueHeaderValue has Name and Value, both strings
        void DemoProxyAuthenticate(HttpResponseMessage response) {
            var h = response.Headers;
            h.ProxyAuthenticate.TryParseAdd("Basic");
            h.ProxyAuthenticate.Add(new HttpChallengeHeaderValue("digest", "token"));
    
            var header = h.ProxyAuthenticate;
            uiLog.Text += "\nPROXY AUTHENTICATE 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("Scheme: {0} Token: {1} Parameters: {2} ToString(): {3}\n", item.Scheme, item.Token, parameterString, item.ToString());
            }
            uiLog.Text += String.Format("ProxyAuthenticate: {0}\n", header.ToString());
        }
    
  • RetryAfter
    RetryAfter
    RetryAfter
    RetryAfter

    Gets or sets the HttpDateOrDeltaHeaderValue object that represent the value of a Retry-After HTTP header on an HTTP response.

    public HttpDateOrDeltaHeaderValue RetryAfter { get; set; }public HttpDateOrDeltaHeaderValue RetryAfter { get; set; }Public ReadWrite Property RetryAfter As HttpDateOrDeltaHeaderValuepublic HttpDateOrDeltaHeaderValue RetryAfter { get; set; }

    Property Value

  • Size
    Size
    Size
    Size

    Gets the number of objects in the HttpResponseHeaderCollection.

    public uint Size { get; }public uint Size { get; }Public ReadOnly Property Size As uintpublic uint Size { get; }

    Property Value

    Remarks

    The Size property returns the true number of items.

    If you are programming using C# or Microsoft Visual Basic, the equivalent method is Count.

  • TransferEncoding
    TransferEncoding
    TransferEncoding
    TransferEncoding

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

    public HttpTransferCodingHeaderValueCollection TransferEncoding { get; }public HttpTransferCodingHeaderValueCollection TransferEncoding { get; }Public ReadOnly Property TransferEncoding As HttpTransferCodingHeaderValueCollectionpublic HttpTransferCodingHeaderValueCollection TransferEncoding { get; }

    Property Value

    Remarks

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

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

    Gets the HttpChallengeHeaderValueCollection of HttpChallengeHeaderValue objects that represent the value of a WWW-Authenticate HTTP header on an HTTP response.

    public HttpChallengeHeaderValueCollection WwwAuthenticate { get; }public HttpChallengeHeaderValueCollection WwwAuthenticate { get; }Public ReadOnly Property WwwAuthenticate As HttpChallengeHeaderValueCollectionpublic HttpChallengeHeaderValueCollection WwwAuthenticate { get; }

    Property Value

    Remarks

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

    // WWW-Authenticate: Basic
    // HttpChallengeHeaderValueCollection
    // HttpChallengeHeaderValue has Scheme and Token (both string) and Parameters (IList<HtpNameValueHeaderValue>)
    // IList<HtpNameValueHeaderValue>
    // HtpNameValueHeaderValue
        void DemoWwwAuthenticate(HttpResponseMessage response) {
            var h = response.Headers;
            h.WwwAuthenticate.TryParseAdd("Basic");
            h.WwwAuthenticate.Add(new HttpChallengeHeaderValue("scheme", "token"));
    
            var header = h.WwwAuthenticate;
            uiLog.Text += "\nWWW AUTHENTICATE 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("Scheme: {0} Token: {1} Parameters: {2} ToString(): {3}\n", item.Scheme, item.Token, parameterString, item.ToString());
            }
            uiLog.Text += String.Format("WwwAuthenticate: {0}\n", header.ToString());
        }
    

Methods

  • Append(String, String)
    Append(String, String)
    Append(String, String)
    Append(String, String)

    Adds a new item to the end of the HttpResponseHeaderCollection.

    public void Append(String name, String value)public void Append(String name, String value)Public Function Append(name As String, value As String) As voidpublic void Append(String name, String value)

    Parameters

    • name
      System.String
      System.String
      System.String
      System.String

      The name of the value to add.

    • value
      System.String
      System.String
      System.String
      System.String

      The item value to add.

  • Clear()
    Clear()
    Clear()
    Clear()

    Removes all objects from the collection.

    public void Clear()public void Clear()Public Function Clear() As voidpublic void Clear()
  • First()
    First()
    First()
    First()

    Retrieves an iterator to the first item in the HttpResponseHeaderCollection.

    public IIterator<IKeyValuePair<string, string>> First()public IIterator<IKeyValuePair<string, string>> First()Public Function First() As IIterator( Of IKeyValuePairstring, string )public IIterator<IKeyValuePair<string, string>> First()

    Returns

    • An object that can be used to enumerate the items in the collection. The iterator points to the first item in the HttpResponseHeaderCollection.

  • GetView()
    GetView()
    GetView()
    GetView()

    Returns an immutable view of the HttpResponseHeaderCollection.

    public IMapView<string, string> GetView()public IMapView<string, string> GetView()Public Function GetView() As IMapView( Of string, string )public IMapView<string, string> GetView()

    Returns

    Remarks

    When programming with .NET, this method is hidden.

  • HasKey(String)
    HasKey(String)
    HasKey(String)
    HasKey(String)

    Determines whether the HttpResponseHeaderCollection contains the specified key.

    public bool HasKey(String key)public bool HasKey(String key)Public Function HasKey(key As String) As boolpublic bool HasKey(String key)

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      The key associated with the item to locate.

    Returns

    • bool
      bool
      bool
      bool

      true if the key is found; otherwise, false.

    Remarks

    When programming with .NET, this method is hidden and developers should use ContainsKey.

  • Insert(String, String)
    Insert(String, String)
    Insert(String, String)
    Insert(String, String)

    Inserts or replaces an item in the HttpResponseHeaderCollection with the specified key and value.

    public bool Insert(String key, String value)public bool Insert(String key, String value)Public Function Insert(key As String, value As String) As boolpublic bool Insert(String key, String value)

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      The key of the item to be inserted.

    • value
      System.String
      System.String
      System.String
      System.String

      The value of the item to insert.

    Returns

    • bool
      bool
      bool
      bool

      true if an item with the specified key is an existing item that was replaced; otherwise false.

    Remarks

    When programming with .NET, this method is hidden and developers should use one of the Add methods.

  • Lookup(String)
    Lookup(String)
    Lookup(String)
    Lookup(String)

    Lookup an item in the HttpResponseHeaderCollection.

    public string Lookup(String key)public string Lookup(String key)Public Function Lookup(key As String) As stringpublic string Lookup(String key)

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      The key of the item to lookup.

    Returns

    • string
      string
      string
      string

      The value, if an item with the specified key exists. Use the HasKey method to determine whether the key exists.

    Remarks

    Use the HasKey(String) method to determine whether the key exists in the HttpResponseHeaderCollection.

    When programming with .NET, this method is hidden and developers should use the Item indexer.

  • Remove(String)
    Remove(String)
    Remove(String)
    Remove(String)

    Removes an item with a given key from the HttpResponseHeaderCollection.

    public void Remove(String key)public void Remove(String key)Public Function Remove(key As String) As voidpublic void Remove(String key)

    Parameters

    • key
      System.String
      System.String
      System.String
      System.String

      Key of the item to be removed.

  • ToString()
    ToString()
    ToString()
    ToString()

    Returns a string that represents the current HttpResponseHeaderCollection object.

    public string ToString()public string ToString()Public Function ToString() As stringpublic string ToString()

    Returns

    • string
      string
      string
      string

      A string that represents the current object.

  • TryAppendWithoutValidation(String, String)
    TryAppendWithoutValidation(String, String)
    TryAppendWithoutValidation(String, String)
    TryAppendWithoutValidation(String, String)

    Try to append the specified item to the HttpResponseHeaderCollection without validation.

    public bool TryAppendWithoutValidation(String name, String value)public bool TryAppendWithoutValidation(String name, String value)Public Function TryAppendWithoutValidation(name As String, value As String) As boolpublic bool TryAppendWithoutValidation(String name, String value)

    Parameters

    • name
      System.String
      System.String
      System.String
      System.String

      The name of the item to append.

    • value
      System.String
      System.String
      System.String
      System.String

      The value of the item to append.

    Returns

    • bool
      bool
      bool
      bool

      true if the item was appended; otherwise false.

    Remarks

    The TryAppendWithoutValidation(String, String) method is available when you need to work with an HTTP header on an HTTP response that doesn't have a strongly-typed class for the HTTP header. If there is a strongly-typed implementation of the HTTP header, then the methods and properties on the strongly-typed class should be used instead of the TryAppendWithoutValidation(String, String) method.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Web.Http.Headers.dll