AuthenticationHeaderParser Class
Namespace: System.Net.Http.Headers
Provides classes that allow you to work with HTTP headers.
Summary
A parser for HTTP authentication headers.
Remarks
This class is not intended for direct use by application developers. It is used internally by the .NET Framework to parse and manage HTTP authentication headers.
Members
| Name | Description |
|---|---|
| Parse |
Parses a string representing an authentication header and returns an
Parameters:
Returns: An Example:
using System.Net.Http.Headers;
public static class Example
{
public static void Main()
{
string authHeader = "Basic dXNlcm5hbWU6cGFzc3dvcmQ=";
try
{
AuthenticationHeaderValue authValue = AuthenticationHeaderParser.Parse(authHeader);
Console.WriteLine($"Scheme: {authValue.Scheme}");
Console.WriteLine($"Parameter: {authValue.Parameter}");
}
catch (FormatException e)
{
Console.WriteLine($"Error parsing header: {e.Message}");
}
}
}
|
| TryParse |
Tries to parse a string representing an authentication header and returns a boolean indicating success.
Parameters:
Returns: Example:
using System.Net.Http.Headers;
public static class Example
{
public static void Main()
{
string authHeader = "Bearer xyz123";
AuthenticationHeaderValue authValue;
if (AuthenticationHeaderParser.TryParse(authHeader, out authValue))
{
Console.WriteLine($"Successfully parsed: Scheme={authValue.Scheme}, Parameter={authValue.Parameter}");
}
else
{
Console.WriteLine("Failed to parse authentication header.");
}
}
}
|