HttpContentHeaderCollection HttpContentHeaderCollection HttpContentHeaderCollection HttpContentHeaderCollection HttpContentHeaderCollection Class

Definition

Provides a collection of the HTTP headers associated with content on an HTTP request or response.

public : sealed class HttpContentHeaderCollection : IIterable<IKeyValuePair<Platform::String, Platform::String>>, IMap<Platform::String, Platform::String>, IStringable, IHttpContentHeaderCollection
struct winrt::Windows::Web::Http::Headers::HttpContentHeaderCollection : IIterable<IKeyValuePair<Platform::String, Platform::String>>, IMap<Platform::String, Platform::String>, IStringable, IHttpContentHeaderCollection
public sealed class HttpContentHeaderCollection : IEnumerable<KeyValuePair<String, String>>, IDictionary<String, String>, IStringable, IHttpContentHeaderCollection
Public NotInheritable Class HttpContentHeaderCollection Implements IEnumerable<KeyValuePair<String, String>>, IDictionary<String, String>, IStringable, IHttpContentHeaderCollection
var httpContentHeaderCollection = new httpContentHeaderCollection();
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following sample code shows a method to get and set headers on HTTP content using the properties on the HttpContentHeaderCollection 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 Windows.Web.Http;
using Windows.Web.Http.Headers;

        public void DemonstrateContentHeader()
        {
            DemonstrateHeaderContentContentDisposition(); 
        }

        public void DemonstrateHeaderContentContentDisposition()
        {
            var content = new HttpStringContent("");
            bool parsedOk = false;

            // Set the header with a string.
            HttpContentDispositionHeaderValue value;
            parsedOk = HttpContentDispositionHeaderValue.TryParse("attachment; filename=\"fname.ext\"", out value);
            content.Headers.ContentDisposition = value;

            // Set the header with a strong type.

            content.Headers.ContentDisposition = new HttpContentDispositionHeaderValue("attachment");
            content.Headers.ContentDisposition.FileName = "myfile.exe";


            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("ContentDisposition filename: {0}={1}", 
                content.Headers.ContentDisposition.DispositionType,
                content.Headers.ContentDisposition.FileName);

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

Remarks

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

The HttpContentHeaderCollection has a constructor and also is returned by the property on HttpBufferContent, HttpFormUrlEncodedContent, HttpMultipartContent, HttpMultipartFormDataContent, HttpStreamContent, and HttpStringContent, classes and the IHttpContent interface.

Enumerating the collection in C# or Microsoft Visual Basic

You can iterate through an HttpContentHeaderCollection 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 with a KeyValuePair of String and String as the constraint.

Constructors

HttpContentHeaderCollection() HttpContentHeaderCollection() HttpContentHeaderCollection() HttpContentHeaderCollection() HttpContentHeaderCollection()

Initializes a new instance of the HttpContentHeaderCollection class.

Properties

ContentDisposition ContentDisposition ContentDisposition ContentDisposition ContentDisposition

Gets or sets the HttpContentDispositionHeaderValue object that represents the value of an HTTP Content-Disposition header on the HTTP content.

ContentEncoding ContentEncoding ContentEncoding ContentEncoding ContentEncoding

Gets the HttpContentCodingHeaderValueCollection of HttpContentCodingHeaderValue objects that represent the value of an HTTP Content-Encoding header on the HTTP content.

ContentLanguage ContentLanguage ContentLanguage ContentLanguage ContentLanguage

Gets the HttpLanguageHeaderValueCollection of objects that represent the value of an HTTP Content-Language header on the HTTP content.

ContentLength ContentLength ContentLength ContentLength ContentLength

Gets or sets the value of the HTTP Content-Length header on the HTTP content.

ContentLocation ContentLocation ContentLocation ContentLocation ContentLocation

Gets or sets the value of the HTTP Content-Location header on the HTTP content.

ContentMD5 ContentMD5 ContentMD5 ContentMD5 ContentMD5

Gets or sets the value of an HTTP Content-MD5 header on the HTTP content.

ContentRange ContentRange ContentRange ContentRange ContentRange

Gets or sets the HttpContentRangeHeaderValue object that represent the value of an HTTP Content-Range header on the HTTP content.

ContentType ContentType ContentType ContentType ContentType

Gets or sets the HttpMediaTypeHeaderValue object that represent the value of an HTTP Content-Type header on the HTTP content.

Expires Expires Expires Expires Expires

Gets or sets the DateTime object that represents the value of an HTTP Expires header on the HTTP content.

Item[TKey] Item[TKey] Item[TKey] Item[TKey] Item[TKey]

Gets or sets the element with the specified key.

Keys Keys Keys Keys Keys

Gets an System.Collections.Generic.ICollection`1 containing the keys of the System.Collections.Generic.IDictionary`2.

LastModified LastModified LastModified LastModified LastModified

Gets or sets the DateTime object that represents the value of an HTTP Last-Modified header on the HTTP content.

Size Size Size Size Size

Gets the number of objects in the HttpContentHeaderCollection.

Values Values Values Values Values

Gets an System.Collections.Generic.ICollection`1 containing the values in the System.Collections.Generic.IDictionary`2.

Methods

Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue) Add(TKey, TValue)

Adds an element with the provided key and value to the System.Collections.Generic.IDictionary`2.

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

Adds a new item to the end of the HttpContentHeaderCollection.

Clear() Clear() Clear() Clear() Clear()

Removes all objects from the HttpContentHeaderCollection.

ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey) ContainsKey(TKey)

Determines whether the System.Collections.Generic.IDictionary`2 contains an element with the specified key.

First() First() First() First() First()

Retrieves an iterator to the first item in the HttpContentHeaderCollection.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator that iterates through the collection.

GetView() GetView() GetView() GetView() GetView()

Returns an immutable view of the HttpContentHeaderCollection.

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

Determines whether the HttpContentHeaderCollection contains the specified key.

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

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

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

Finds an item in the HttpContentHeaderCollection if it exists.

Remove(T) Remove(T) Remove(T) Remove(T) Remove(T)

Removes the element with the specified key from the System.Collections.Generic.IDictionary`2.

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

Removes a specific object from the HttpContentHeaderCollection.

ToString() ToString() ToString() ToString() ToString()

Returns a string that represents the current HttpContentHeaderCollection object.

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

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

TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue) TryGetValue(TKey, out TValue)

Gets the value associated with the specified key.

See Also