Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HttpContentHeaderCollection class

Applies to Windows and Windows Phone

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

Syntax


var httpContentHeaderCollection = new Windows.Web.Http.Headers.HttpContentHeaderCollection();

Attributes

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06030000)]

Members

The HttpContentHeaderCollection class has these types of members:

Constructors

The HttpContentHeaderCollection class has these constructors.

ConstructorDescription
HttpContentHeaderCollection Initializes a new instance of the HttpContentHeaderCollection class.

 

Methods

The HttpContentHeaderCollection class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
Add(KeyValuePair) [C#, VB]Adds a new key-value pair to the HttpContentHeaderCollection.
Add(String) [C#, VB]Adds an item to the HttpContentHeaderCollection.
Append Adds a new item to the end of the HttpContentHeaderCollection.
Clear Removes all objects from the HttpContentHeaderCollection.
Contains [C#, VB]Returns a value that indicates whether a specified key-value pair exists in the HttpContentHeaderCollection.
ContainsKey [C#, VB]Returns a value that indicates whether a specified key exists in the HttpContentHeaderCollection.
CopyTo [C#, VB]Copies the elements of the collection to an array, starting at a particular array index.
First [C++, JavaScript]Retrieves an iterator to the first item in the HttpContentHeaderCollection.
GetView [C++, JavaScript]Returns an immutable view of the HttpContentHeaderCollection.
HasKey [C++, JavaScript]Determines whether the HttpContentHeaderCollection contains the specified key.
Insert [C++, JavaScript]Inserts or replaces an item in the HttpContentHeaderCollection with the specified key and value.
Lookup [C++, JavaScript]Lookup an item in the HttpContentHeaderCollection.
Remove [C++, JavaScript]Removes a specific object from the HttpContentHeaderCollection .
Remove(KeyValuePair) [C#, VB]Removes a specific key-value pair from the HttpContentHeaderCollection.
Remove(String) [C#, VB]Removes a specific item from the HttpContentHeaderCollection.
ToString Returns a string that represents the current HttpContentHeaderCollection object.
TryAppendWithoutValidation Try to append the specified item to the HttpContentHeaderCollection without validation.
TryGetValue [C#, VB]Returns a value that indicates whether a specified key exists in the HttpContentHeaderCollection. If an item with that key exists, the item is retrieved as an out parameter.

 

Properties

The HttpContentHeaderCollection class has these properties.

PropertyAccess typeDescription

ContentDisposition

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

ContentEncoding

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

ContentLanguage

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

ContentLength

Read/writeGets or sets the value of the HTTP Content-Length header on the HTTP content.

ContentLocation

Read/writeGets or sets the value of the HTTP Content-Location header on the HTTP content.

ContentMD5

Read/writeGets or sets the value of an HTTP Content-MD5 header on the HTTP content.

ContentRange

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

ContentType

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

Count [C#, VB]

Read-onlyGets the number of elements contained in the collection.

Expires

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

IsReadOnly [C#, VB]

Read-onlyGets a value indicating whether the dictionary is read-only.

Item [C#, VB]

Read/writeGets or sets the element value at the specified key index.

Keys [C#, VB]

Read-onlyGets an ICollection object containing the keys of the HttpContentHeaderCollection.

LastModified

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

Size [C++, JavaScript]

Read-onlyGets the number of objects in the HttpContentHeaderCollection.

Values [C#, VB]

Read-onlyGets an ICollection object containing the values of the HttpContentHeaderCollection .

 

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 Headers 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<T> with a KeyValuePair of String and String as the constraint.

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

 

Requirements

Minimum supported client

Windows 8.1 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 R2 [Windows Store apps, desktop apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Web.Http.Headers
Windows::Web::Http::Headers [C++]

Metadata

Windows.winmd

See also

HttpBufferContent
HttpFormUrlEncodedContent
HttpMultipartContent
HttpMultipartFormDataContent
HttpRequestMessage
HttpResponseMessage
HttpStreamContent
HttpStringContent
Object
IMap(String, String)
IIterable(IKeyValuePair)
IStringable

 

 

Show:
© 2014 Microsoft. All rights reserved.