共用方式為


HttpCookiePairHeaderValueCollection 類別

定義

表示 HTTP 要求上 Cookie HTTP 標頭的值。

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

Windows 需求

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

範例

下列範例程式碼示範使用 HttpCookiePairHeaderValueCollection 和HttpCookiePairHeaderValue類別的屬性和方法,取得和設定HttpRequestMessage物件上的Cookie HTTP 標頭的方法。

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

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

            // Set the header with a string.
            parsedOk = request.Headers.Cookie.TryParseAdd("cookieName=cookieValue");

            // Set the header with a strong type.
            request.Headers.Cookie.Add(new HttpCookiePairHeaderValue("cookie2", "value2"));

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

備註

HttpCookiePairHeaderValueCollection 類別代表 HTTP 要求上 Cookie HTTP 標頭的值。

HttpCookiePairHeaderValueCollection 為Cookie HTTP 標頭中 Cookie 資訊所使用的HttpCookiePairHeaderValue類別實例提供集合容器。

HttpRequestHeaderCollection上的Cookie屬性會傳回 HttpCookiePairHeaderValueCollection 物件

屬性

Size

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

方法

Append(HttpCookiePairHeaderValue)

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

Clear()

從集合中移除所有物件。

First()

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

GetAt(UInt32)

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

GetMany(UInt32, HttpCookiePairHeaderValue[])

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

GetView()

傳回 HttpCookiePairHeaderValueCollection的不可變檢視。

IndexOf(HttpCookiePairHeaderValue, UInt32)

擷取集合中 HttpCookiePairHeaderValue 的索引。

InsertAt(UInt32, HttpCookiePairHeaderValue)

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

ParseAdd(String)

剖析並新增 專案至 HttpCookiePairHeaderValueCollection

RemoveAt(UInt32)

HttpCookiePairHeaderValueCollection移除位於指定索引處的專案。

RemoveAtEnd()

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

ReplaceAll(HttpCookiePairHeaderValue[])

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

SetAt(UInt32, HttpCookiePairHeaderValue)

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

ToString()

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

TryParseAdd(String)

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

適用於

另請參閱