Dela via


HttpMediaTypeWithQualityHeaderValueCollection Class

Definition

Represents the value of the Accept HTTP header on an HTTP request.

public ref class HttpMediaTypeWithQualityHeaderValueCollection sealed : IIterable<HttpMediaTypeWithQualityHeaderValue ^>, IVector<HttpMediaTypeWithQualityHeaderValue ^>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HttpMediaTypeWithQualityHeaderValueCollection final : IIterable<HttpMediaTypeWithQualityHeaderValue>, IVector<HttpMediaTypeWithQualityHeaderValue>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HttpMediaTypeWithQualityHeaderValueCollection final : IIterable<HttpMediaTypeWithQualityHeaderValue>, IVector<HttpMediaTypeWithQualityHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HttpMediaTypeWithQualityHeaderValueCollection : IEnumerable<HttpMediaTypeWithQualityHeaderValue>, IList<HttpMediaTypeWithQualityHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class HttpMediaTypeWithQualityHeaderValueCollection : IEnumerable<HttpMediaTypeWithQualityHeaderValue>, IList<HttpMediaTypeWithQualityHeaderValue>, IStringable
Public NotInheritable Class HttpMediaTypeWithQualityHeaderValueCollection
Implements IEnumerable(Of HttpMediaTypeWithQualityHeaderValue), IList(Of HttpMediaTypeWithQualityHeaderValue), IStringable
Inheritance
Object Platform::Object IInspectable HttpMediaTypeWithQualityHeaderValueCollection
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

The following sample code shows a method to get and set the Accept HTTP header on an HttpRequestMessage object using the properties and methods on the HttpMediaTypeWithQualityHeaderValueCollection and HttpMediaTypeWithQualityHeaderValue classes.

using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

        public void DemonstrateHeaderRequestAccept()
        {
            var request = new HttpRequestMessage();
            bool parsedOk = false;

            // Set the header with a string.
            parsedOk = request.Headers.Accept.TryParseAdd ("audio/*");
            parsedOk = request.Headers.Accept.TryParseAdd ("audio/*; q=0.2");
            parsedOk = request.Headers.Accept.TryParseAdd ("audio/*; q=0.4; mysetting=myvalue");

            // Set the header with a strong type.
            request.Headers.Accept.Add(new HttpMediaTypeWithQualityHeaderValue("audio/*", .6));

            // Get the strong type out
            foreach (var value in request.Headers.Accept)
            {
                System.Diagnostics.Debug.WriteLine("One of the Accept values: {0}={1}", value.MediaType, value.Quality);
            }

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

Remarks

The HttpMediaTypeWithQualityHeaderValueCollection represents the value of the Accept HTTP header on an HTTP request.

The HttpMediaTypeWithQualityHeaderValueCollection is a collection of HttpMediaTypeWithQualityHeaderValue objects used for accept information in the HTTP Accept header.

The Accept property on the HttpRequestHeaderCollection returns an HttpMediaTypeWithQualityHeaderValueCollection object.

Properties

Size

Gets the number of HttpMediaTypeWithQualityHeaderValue objects in the collection.

Methods

Append(HttpMediaTypeWithQualityHeaderValue)

Adds a new HttpMediaTypeWithQualityHeaderValue item to the end of the collection.

Clear()

Removes all objects from the collection.

First()

Retrieves an iterator to the first HttpMediaTypeWithQualityHeaderValue item in the collection.

GetAt(UInt32)

Returns the HttpMediaTypeWithQualityHeaderValue at the specified index in the collection.

GetMany(UInt32, HttpMediaTypeWithQualityHeaderValue[])

Retrieves the HttpMediaTypeWithQualityHeaderValue items that start at the specified index in the collection.

GetView()

Returns an immutable view of the HttpMediaTypeWithQualityHeaderValueCollection.

IndexOf(HttpMediaTypeWithQualityHeaderValue, UInt32)

Retrieves the index of an HttpMediaTypeWithQualityHeaderValue in the collection.

InsertAt(UInt32, HttpMediaTypeWithQualityHeaderValue)

Inserts an HttpMediaTypeWithQualityHeaderValue into the collection at the specified index.

ParseAdd(String)

Parses and adds an entry to the HttpMediaTypeWithQualityHeaderValueCollection.

RemoveAt(UInt32)

Removes the entry at the specified index from the HttpMediaTypeWithQualityHeaderValueCollection.

RemoveAtEnd()

Removes the last HttpMediaTypeWithQualityHeaderValue item from the collection.

ReplaceAll(HttpMediaTypeWithQualityHeaderValue[])

Replaces all the HttpMediaTypeWithQualityHeaderValue items in the collection with the specified HttpMediaTypeWithQualityHeaderValue items.

SetAt(UInt32, HttpMediaTypeWithQualityHeaderValue)

Sets the HttpMediaTypeWithQualityHeaderValue at the specified index in the collection.

ToString()

Returns a string that represents the current HttpMediaTypeWithQualityHeaderValueCollection object.

TryParseAdd(String)

Tries to parse and add the specified item to the HttpMediaTypeWithQualityHeaderValueCollection.

Applies to

See also