HttpProductInfoHeaderValueCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示 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
- 繼承
- 屬性
- 實作
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 物件數目。 |