SchemedBasedHeaderValue Class
Namespace: System.Net.Http.Headers
Assembly: System.Net.Http (in System.Net.Http.dll)
Assembly: System.Net.Http (in System.Net.Http.dll)
Represents a custom header value that includes a scheme.
Syntax
public abstract class SchemedBasedHeaderValue
Remarks
This is an abstract base class for header values that are composed of a scheme and optional parameters. Examples include AuthenticationHeaderValue and ViaHeaderValue.
This class provides common functionality for parsing and formatting header values that start with a scheme name.
Constructors
No public constructors are available as this is an abstract class. Derived classes will provide their own constructors.
Properties
Scheme
string Scheme { get; }
Gets the scheme part of the header value.
Parameters
readonly System.Collections.Generic.ICollection<System.Net.Http.NameValueHeaderValue> Parameters { get; }
Gets the collection of parameters associated with the header value.
Parameters are represented as name-value pairs.
Methods
TryParse
static bool TryParse(string input, out SchemedBasedHeaderValue parsedValue)
Parses a string into an instance of a derived
SchemedBasedHeaderValue class.
Parameters:
input:
The string to parse.
stringThe string to parse.
parsedValue:
When this method returns, contains the parsed
out SchemedBasedHeaderValueWhen this method returns, contains the parsed
SchemedBasedHeaderValue instance, if the parse succeeded, or null if it failed.
ToString
override string ToString()
Returns a string representation of the header value.
Derived Classes
Example
using System;
using System.Net.Http.Headers;
public class Example
{
public static void Main(string[] args)
{
string headerString = "Digest realm=\"example.com\", nonce=\"dcd98b7102dd2f0e8b9475c75125b710\"";
if (AuthenticationHeaderValue.TryParse(headerString, out AuthenticationHeaderValue parsedHeader))
{
Console.WriteLine($"Scheme: {parsedHeader.Scheme}"); // Output: Scheme: Digest
Console.WriteLine($"Parameters:");
foreach (var param in parsedHeader.Parameters)
{
Console.WriteLine($"- {param.Name}: {param.Value}");
}
// Output:
// Parameters:
// - realm: "example.com"
// - nonce: "dcd98b7102dd2f0e8b9475c75125b710"
}
else
{
Console.WriteLine("Failed to parse header value.");
}
}
}