RetryConditionHeaderValue Class
System.Net.Http.Headers
Represents the value of the Retry-Condition HTTP header.
Constructors
Properties
-
public DateTimeOffset LastResponseDate { get; }
Gets the date and time of the last response.
-
public TimeSpan RetryAfter { get; }
Gets the retry-after interval.
Methods
-
public override bool Equals(object obj)
Determines whether the specified object is equal to the current object.
-
public bool Equals(RetryConditionHeaderValue other)
-
public override int GetHashCode()
Serves as the default hash function.
-
public override string ToString()
Returns a string that represents the current object.
-
public static RetryConditionHeaderValue Parse(string input)
-
public static bool TryParse(string input, [out] RetryConditionHeaderValue value)
Examples
using System;
using System.Net.Http.Headers;
public class Example
{
public static void Main()
{
// Example 1: Using Retry-After date
var retryDate = new DateTimeOffset(2023, 10, 27, 10, 30, 0, TimeSpan.Zero);
var retryConditionByDate = new RetryConditionHeaderValue(retryDate);
Console.WriteLine($"Retry-After: {retryConditionByDate.LastResponseDate}");
// Output: Retry-After: 2023-10-27 10:30:00 +00:00
// Example 2: Using Retry-After interval
var retryInterval = TimeSpan.FromSeconds(60);
var retryConditionByInterval = new RetryConditionHeaderValue(retryInterval);
Console.WriteLine($"Retry-After: {retryConditionByInterval.RetryAfter}");
// Output: Retry-After: 00:01:00
// Example 3: Parsing a Retry-After header string
string headerString = "date: Fri, 27 Oct 2023 10:30:00 GMT";
if (RetryConditionHeaderValue.TryParse(headerString, out var parsedRetryCondition))
{
Console.WriteLine($"Parsed Retry-After Date: {parsedRetryCondition.LastResponseDate}");
}
headerString = "120"; // Seconds
if (RetryConditionHeaderValue.TryParse(headerString, out parsedRetryCondition))
{
Console.WriteLine($"Parsed Retry-After Interval: {parsedRetryCondition.RetryAfter}");
}
}
}
See Also