HttpMediaTypeWithQualityHeaderValueCollection 類別

定義

表示 HTTP 要求上 接受 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物件上的Accept HTTP 標頭的方法。

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

適用於

另請參閱