System.Net.Http.Headers
Namespace: System.Net.Http.Headers
ProductInfoHeaderValue
Represents a value for the ProductInfoHeaderValue header.
Syntax
public class ProductInfoHeaderValue : IEquatable<ProductInfoHeaderValue>, ICloneable
Remarks
The ProductInfoHeaderValue class represents the value of the ProductInfoHeaderValue header, which is used to provide product information.
This header is commonly used in HTTP requests to identify the client software making the request. For example, it can be used to specify the name and version of the application, such as MyClient/1.0 or MyApp/2.5 (Windows).
You can create instances of this class to set the ProductInfoHeaderValue header on an HttpRequestMessage.
Properties
| Name | Description |
|---|---|
ProductInfo |
Gets the product information. |
Comment |
Gets the comment associated with the product information. |
Constructors
| Signature | Description |
|---|---|
ProductInfoHeaderValue(string productName)
|
Initializes a new instance of the ProductInfoHeaderValue class with the specified product name. |
ProductInfoHeaderValue(string productName, string productVersion)
|
Initializes a new instance of the ProductInfoHeaderValue class with the specified product name and version. |
ProductInfoHeaderValue(string productName, Version productVersion)
|
Initializes a new instance of the ProductInfoHeaderValue class with the specified product name and version. |
ProductInfoHeaderValue(string productName, string productVersion, string comment)
|
Initializes a new instance of the ProductInfoHeaderValue class with the specified product name, version, and comment. |
Methods
| Signature | Description |
|---|---|
Equals(object obj)
|
Determines whether the specified object is equal to the current object. |
Equals(ProductInfoHeaderValue other)
|
Indicates whether the current object is equal to another object of the same type. |
GetHashCode()
|
Serves as the default hash function. |
GetType()
|
Gets the Type of the current instance. |
Parse(string input)
|
Parses a string into a ProductInfoHeaderValue instance. |
ToString()
|
Returns a string that represents the current object. |
TryParse(string input, out ProductInfoHeaderValue parsedValue)
|
Tries to parse a string into a ProductInfoHeaderValue instance. |
Usage Example
The following example demonstrates how to create and use ProductInfoHeaderValue:
using System.Net.Http;
using System.Net.Http.Headers;
public class Example
{
public static void Main(string[] args)
{
var request = new HttpRequestMessage(HttpMethod.Get, "https://example.com");
// Create a ProductInfoHeaderValue with name and version
var productInfo = new ProductInfoHeaderValue("MyAwesomeApp", "1.2.3");
request.Headers.UserAgent.Add(productInfo);
// Create a ProductInfoHeaderValue with name, version, and comment
var anotherProductInfo = new ProductInfoHeaderValue("AnotherClient", "4.0", "Running on macOS");
request.Headers.UserAgent.Add(anotherProductInfo);
// The User-Agent header will be "MyAwesomeApp/1.2.3 AnotherClient/4.0 (Running on macOS)"
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
// Send the request...
// var response = client.SendAsync(request).GetAwaiter().GetResult();
}
}