HttpMediaTypeWithQualityHeaderValueCollection 类

定义

表示 HTTP 请求上的 Accept HTTP 标头的值。

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
继承
Object Platform::Object IInspectable HttpMediaTypeWithQualityHeaderValueCollection
属性
实现

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

以下示例代码演示了一个方法,该方法使用 HttpMediaTypeWithQualityHeaderValueCollection 和 HttpMediaTypeWithQualityHeaderValue 类上的属性和方法获取和设置 HttpRequestMessage 对象上的 AcceptHTTP 标头。

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

注解

HttpMediaTypeWithQualityHeaderValueCollection 表示 HTTP 请求上的 Accept HTTP 标头的值。

HttpMediaTypeWithQualityHeaderValueCollection 是 HttpMediaTypeWithQualityHeaderValue 对象的集合,用于接受 HTTP Accept 标头中的信息。

HttpRequestHeaderCollection 上的 Accept 属性返回 HttpMediaTypeWithQualityHeaderValueCollection 对象。

属性

Size

获取集合中 HttpMediaTypeWithQualityHeaderValue 对象的数目。

方法

Append(HttpMediaTypeWithQualityHeaderValue)

将新的 HttpMediaTypeWithQualityHeaderValue 项添加到集合的末尾。

Clear()

从集合中删除所有对象。

First()

检索集合中第一个 HttpMediaTypeWithQualityHeaderValue 项的迭代器。

GetAt(UInt32)

返回集合中指定索引处的 HttpMediaTypeWithQualityHeaderValue

GetMany(UInt32, HttpMediaTypeWithQualityHeaderValue[])

检索从集合中的指定索引处开始的 HttpMediaTypeWithQualityHeaderValue 项。

GetView()

返回 HttpMediaTypeWithQualityHeaderValueCollection 的不可变视图。

IndexOf(HttpMediaTypeWithQualityHeaderValue, UInt32)

检索集合中 HttpMediaTypeWithQualityHeaderValue 的索引。

InsertAt(UInt32, HttpMediaTypeWithQualityHeaderValue)

HttpMediaTypeWithQualityHeaderValue 插入集合中的指定索引处。

ParseAdd(String)

分析和添加 HttpMediaTypeWithQualityHeaderValueCollection 的条目。

RemoveAt(UInt32)

HttpMediaTypeWithQualityHeaderValueCollection 中删除指定索引处的条目。

RemoveAtEnd()

从集合中删除最后一个 HttpMediaTypeWithQualityHeaderValue 项。

ReplaceAll(HttpMediaTypeWithQualityHeaderValue[])

将集合中的所有 HttpMediaTypeWithQualityHeaderValue 项替换为指定的 HttpMediaTypeWithQualityHeaderValue 项。

SetAt(UInt32, HttpMediaTypeWithQualityHeaderValue)

在集合中的指定索引处设置 HttpMediaTypeWithQualityHeaderValue

ToString()

返回表示当前 HttpMediaTypeWithQualityHeaderValueCollection 对象的字符串。

TryParseAdd(String)

尝试分析指定项并将其添加到 HttpMediaTypeWithQualityHeaderValueCollection

适用于

另请参阅