HttpProductInfoHeaderValueCollection 類別

定義

表示 HTTP 要求上 User-Agent HTTP 標頭的值。

public ref class HttpProductInfoHeaderValueCollection sealed : IIterable<HttpProductInfoHeaderValue ^>, IVector<HttpProductInfoHeaderValue ^>, 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 HttpProductInfoHeaderValueCollection final : IIterable<HttpProductInfoHeaderValue>, IVector<HttpProductInfoHeaderValue>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HttpProductInfoHeaderValueCollection final : IIterable<HttpProductInfoHeaderValue>, IVector<HttpProductInfoHeaderValue>, 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 HttpProductInfoHeaderValueCollection : IEnumerable<HttpProductInfoHeaderValue>, IList<HttpProductInfoHeaderValue>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class HttpProductInfoHeaderValueCollection : IEnumerable<HttpProductInfoHeaderValue>, IList<HttpProductInfoHeaderValue>, IStringable
Public NotInheritable Class HttpProductInfoHeaderValueCollection
Implements IEnumerable(Of HttpProductInfoHeaderValue), IList(Of HttpProductInfoHeaderValue), IStringable
繼承
Object Platform::Object IInspectable HttpProductInfoHeaderValueCollection
屬性
實作

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

下列範例程式碼示範在HttpRequestMessage物件上使用 HttpProductInfoHeaderValueCollection 和HttpProductInfoHeaderValue類別的屬性和方法,取得及設定User-Agent HTTP 標頭的方法。

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

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

            // Set the header with a string.
            parsedOk = request.Headers.UserAgent.TryParseAdd("testprogram/1.0");

            // Set the header with a strong type.
            request.Headers.UserAgent.Add(new HttpProductInfoHeaderValue("myprogram", "2.2"));

            // Get the strong type out 
            foreach (var value in request.Headers.UserAgent) {
                System.Diagnostics.Debug.WriteLine("One of the UserAgent values: {0} / {1}", value.Product.Name, value.Product.Version);
            }

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

備註

HttpProductInfoHeaderValueCollection 代表 HTTP 要求上 User-Agent HTTP 標頭的值。

HttpProductInfoHeaderValueCollection 是 HttpProductInfoHeaderValue 物件的集合,用於 HTTP User-Agent 標頭中的產品資訊。

User-Agent標頭包含產生要求之使用者代理程式的相關資訊。 User-Agent標頭可以包含多個產品權杖,以及識別使用者代理程式和任何子產品的批註。

HttpRequestHeaderCollection上的UserAgent屬性會傳回 HttpProductInfoHeaderValueCollection 物件。

屬性

Size

取得集合中的 HttpProductInfoHeaderValue 物件數目。

方法

Append(HttpProductInfoHeaderValue)

將新的 HttpProductInfoHeaderValue 專案新增至集合結尾。

Clear()

從集合中移除所有物件。

First()

擷取反覆運算器至集合中的第一個 HttpProductInfoHeaderValue 專案。

GetAt(UInt32)

傳回集合中指定索引處的 HttpProductInfoHeaderValue

GetMany(UInt32, HttpProductInfoHeaderValue[])

擷取從集合中指定索引處開始的 HttpProductInfoHeaderValue 專案。

GetView()

傳回 HttpProductInfoHeaderValueCollection的不可變檢視。

IndexOf(HttpProductInfoHeaderValue, UInt32)

擷取集合中 HttpProductInfoHeaderValue 的索引。

InsertAt(UInt32, HttpProductInfoHeaderValue)

HttpProductInfoHeaderValue 插入集合中指定的索引處。

ParseAdd(String)

剖析並新增專案至 HttpProductInfoHeaderValueCollection

RemoveAt(UInt32)

從 HttpMethodHeaderValueCollection 中移除位於指定索引處的專案。

RemoveAtEnd()

從集合中移除最後一個 HttpProductInfoHeaderValue 專案。

ReplaceAll(HttpProductInfoHeaderValue[])

以指定的HttpProductInfoHeaderValue 專案取代集合中的所有 HttpProductInfoHeaderValue專案。

SetAt(UInt32, HttpProductInfoHeaderValue)

在集合中指定的索引處設定 HttpProductInfoHeaderValue

ToString()

會傳回代表目前 HttpProductInfoHeaderValueCollection 物件的字串。

TryParseAdd(String)

嘗試剖析並新增指定的專案至 HttpProductInfoHeaderValueCollection

適用於

另請參閱