HttpProductInfoHeaderValueCollection Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents the value of the User-Agent HTTP header on an HTTP request.
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
- Inheritance
- Attributes
- Implements
Windows requirements
Device family |
Windows 10 (introduced in 10.0.10240.0)
|
API contract |
Windows.Foundation.UniversalApiContract (introduced in v1.0)
|
Examples
The following sample code shows a method to get and set the User-Agent HTTP header on an HttpRequestMessage object using the properties and methods on the HttpProductInfoHeaderValueCollection and HttpProductInfoHeaderValue classes.
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());
}
Remarks
The HttpProductInfoHeaderValueCollection represents the value of the User-Agent HTTP header on an HTTP request.
The HttpProductInfoHeaderValueCollection is a collection of HttpProductInfoHeaderValue objects used for product information in the HTTP User-Agent header.
The User-Agent header contains information about the user agent originating the request. The User-Agent header can contain multiple product tokens and comments identifying the user agent and any sub-products.
The UserAgent property on the HttpRequestHeaderCollection returns an HttpProductInfoHeaderValueCollection object.
Properties
Size |
Gets the number of HttpProductInfoHeaderValue objects in the collection. |
Methods
Append(HttpProductInfoHeaderValue) |
Adds a new HttpProductInfoHeaderValue item to the end of the collection. |
Clear() |
Removes all objects from the collection. |
First() |
Retrieves an iterator to the first HttpProductInfoHeaderValue item in the collection. |
GetAt(UInt32) |
Returns the HttpProductInfoHeaderValue at the specified index in the collection. |
GetMany(UInt32, HttpProductInfoHeaderValue[]) |
Retrieves the HttpProductInfoHeaderValue items that start at the specified index in the collection. |
GetView() |
Returns an immutable view of the HttpProductInfoHeaderValueCollection. |
IndexOf(HttpProductInfoHeaderValue, UInt32) |
Retrieves the index of an HttpProductInfoHeaderValue in the collection. |
InsertAt(UInt32, HttpProductInfoHeaderValue) |
Inserts an HttpProductInfoHeaderValue into the collection at the specified index. |
ParseAdd(String) |
Parses and adds an entry to the HttpProductInfoHeaderValueCollection. |
RemoveAt(UInt32) |
Removes the entry at the specified index from the HttpMethodHeaderValueCollection. |
RemoveAtEnd() |
Removes the last HttpProductInfoHeaderValue item from the collection. |
ReplaceAll(HttpProductInfoHeaderValue[]) |
Replaces all the HttpProductInfoHeaderValue items in the collection with the specified HttpProductInfoHeaderValue items. |
SetAt(UInt32, HttpProductInfoHeaderValue) |
Sets the HttpProductInfoHeaderValue at the specified index in the collection. |
ToString() |
Returns a string that represents the current HttpProductInfoHeaderValueCollection object. |
TryParseAdd(String) |
Tries to parse and add the specified item to the HttpProductInfoHeaderValueCollection. |