Represents the value of the Warning HTTP header.
Namespace: System.Net.Http.Headers
Assembly: System.Net.Http.Formatting.dll
public sealed class WarningHeaderValue
The Warning header provides a way to indicate that the client, a proxy, or a gateway has made a modification to the message which is likely to be important to the user or another system.
The WarningHeaderValue class provides a convenient way to parse and construct Warning header values according to RFC 7234.
Initializes a new instance of the WarningHeaderValue class with the specified agent, code, and text.
public WarningHeaderValue(string agent, int code, string text);
Initializes a new instance of the WarningHeaderValue class with the specified agent, code, text, and date.
public WarningHeaderValue(string agent, int code, string text, DateTimeOffset date);
Gets the agent that generated the warning.
Gets the warning code.
Gets the date and time the warning was generated.
Gets the warning text.
Determines whether the specified object is equal to the current object.
public override bool Equals(object obj);
Serves as the default hash function.
public override int GetHashCode();
Parses a Warning header value from the specified string.
public static WarningHeaderValue Parse(string input);
Returns a string representation of the current WarningHeaderValue object.
public override string ToString();
Tries to parse a Warning header value from the specified string.
public static bool TryParse(string input, out WarningHeaderValue result);
The following example demonstrates how to create and add a WarningHeaderValue to an HTTP request.
using System;
using System.Net.Http;
using System.Net.Http.Headers;
public class Example
{
public static void Main()
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://example.com");
// Create a WarningHeaderValue
var warning = new WarningHeaderValue("my-agent", 110, "Response is stale");
request.Headers.Warning.Add(warning);
// You can also include a date
var warningWithDate = new WarningHeaderValue("another-agent", 199, "Content modified", DateTimeOffset.UtcNow);
request.Headers.Warning.Add(warningWithDate);
// Send the request...
// var response = await client.SendAsync(request);
// Console.WriteLine(response);
}
}