HttpCredentialsHeaderValue HttpCredentialsHeaderValue HttpCredentialsHeaderValue HttpCredentialsHeaderValue HttpCredentialsHeaderValue Class

Definition

Represents the value of the Authorization or Proxy-Authorization HTTP header on an HTTP request.

public : sealed class HttpCredentialsHeaderValue : IStringable, IHttpCredentialsHeaderValue
struct winrt::Windows::Web::Http::Headers::HttpCredentialsHeaderValue : IStringable, IHttpCredentialsHeaderValue
public sealed class HttpCredentialsHeaderValue : IStringable, IHttpCredentialsHeaderValue
Public NotInheritable Class HttpCredentialsHeaderValue Implements IStringable, IHttpCredentialsHeaderValue
var httpCredentialsHeaderValue = new httpCredentialsHeaderValue(scheme);
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

The following sample code shows a method to get and set the Authorization HTTP header on an HttpRequestMessage object using the properties and methods on the HttpCredentialsHeaderValue class.

using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

        public void DemonstrateHeaderRequestAuthorization() {
            var request = new HttpRequestMessage();

            // Set the header with a strong type.
            string username = "user";
            string password = "password";
            var buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary (username + ":" + password, Windows.Security.Cryptography.BinaryStringEncoding.Utf16LE);
            string base64token = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(buffer);
            request.Headers.Authorization = new HttpCredentialsHeaderValue("Basic", base64token);


            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("One of the Authorization values: {0}={1}", 
                request.Headers.Authorization.Scheme,
                request.Headers.Authorization.Token);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The Authorization ToString() results: {0}", request.Headers.Authorization.ToString());
        }

The following sample code shows a method to get and set the Proxy-Authorization HTTP header on an HttpRequestMessage object using the properties and methods on the HttpCredentialsHeaderValue class.

using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

        public void DemonstrateHeaderRequestProxyAuthorization() {
            var request = new HttpRequestMessage();

            // Set the header with a strong type.
            string username = "user";
            string password = "password";
            var buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary(username + ":" + password, Windows.Security.Cryptography.BinaryStringEncoding.Utf16LE);
            string base64token = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(buffer);
            request.Headers.ProxyAuthorization = new HttpCredentialsHeaderValue("Basic", base64token);


            // Get the strong type out
            System.Diagnostics.Debug.WriteLine("One of the ProxyAuthorixation values: {0}={1}",
                request.Headers.ProxyAuthorization.Scheme,
                request.Headers.ProxyAuthorization.Token);

            // The ToString() is useful for diagnostics, too.
            System.Diagnostics.Debug.WriteLine("The ProxyAuthorization ToString() results: {0}", request.Headers.ProxyAuthorization.ToString());
        }

Remarks

The HttpCredentialsHeaderValue class represents the Authorization or Proxy-Authorization HTTP header on an HTTP request.

The Authorization property on the HttpRequestHeaderCollection returns an HttpCredentialsHeaderValue object that represents the Authorization HTTP header. The ProxyAuthorization property on the HttpRequestHeaderCollection returns an HttpCredentialsHeaderValue object that represents the Proxy-Authorization HTTP header.

Constructors

HttpCredentialsHeaderValue(String) HttpCredentialsHeaderValue(String) HttpCredentialsHeaderValue(String) HttpCredentialsHeaderValue(String) HttpCredentialsHeaderValue(String)

Initializes a new instance of the HttpCredentialsHeaderValue class with the scheme to use for authentication.

public : HttpCredentialsHeaderValue(Platform::String scheme)
HttpCredentialsHeaderValue(winrt::hstring scheme) const;
public HttpCredentialsHeaderValue(String scheme)
Public Sub New(scheme As String)
var httpCredentialsHeaderValue = new httpCredentialsHeaderValue(scheme);
Parameters
scheme
String String String

The scheme to use for authentication.

See Also

HttpCredentialsHeaderValue(String, String) HttpCredentialsHeaderValue(String, String) HttpCredentialsHeaderValue(String, String) HttpCredentialsHeaderValue(String, String) HttpCredentialsHeaderValue(String, String)

Initializes a new instance of the HttpCredentialsHeaderValue class with the scheme and user token information to use for authentication.

public : HttpCredentialsHeaderValue(Platform::String scheme, Platform::String token)
HttpCredentialsHeaderValue(winrt::hstring scheme, winrt::hstring token) const;
public HttpCredentialsHeaderValue(String scheme, String token)
Public Sub New(scheme As String, token As String)
var httpCredentialsHeaderValue = new httpCredentialsHeaderValue(scheme, token);
Parameters
scheme
String String String

The scheme to use for authentication.

token
String String String

The user token information to use for authentication.

See Also

Properties

Parameters Parameters Parameters Parameters Parameters

Gets a set of name/value pairs included in the Authorization or Proxy-Authorization HTTP header.

public : IVector<HttpNameValueHeaderValue> Parameters { get; }
IVector<HttpNameValueHeaderValue> Parameters();
public IList<HttpNameValueHeaderValue> Parameters { get; }
Public ReadOnly Property Parameters As IList<HttpNameValueHeaderValue>
var iList = httpCredentialsHeaderValue.parameters;
Value
IList<HttpNameValueHeaderValue> IList<HttpNameValueHeaderValue> IList<HttpNameValueHeaderValue>

A set of name/value pairs.

Remarks

The Parameters property gets a set of name/value pairs of the credentials containing the authentication information of the user agent for the resource being requested.

An HttpCredentialsHeaderValue object has a Scheme and either a Token or a Parameters list. So either the Parameters property is an empty collection or the Token property is an empty string.

Scheme Scheme Scheme Scheme Scheme

Gets the scheme to use for authentication.

public : Platform::String Scheme { get; }
winrt::hstring Scheme();
public string Scheme { get; }
Public ReadOnly Property Scheme As string
var string = httpCredentialsHeaderValue.scheme;
Value
string string string

The scheme to use for authentication.

Remarks

The Scheme property scheme to use for authentication of the user agent for the resource being requested.

An HttpCredentialsHeaderValue object has a Scheme and either a Token or a Parameters list. So either the Parameters property is an empty collection or the Token property is an empty string.

Each authentication scheme defines the syntax to use for authentication. Basic authentication, for example, uses base64 encoding of the userid and passwd elements in the Token property. Digest authentication would use a Parameters list of name/value pairs. Basic authentication and digest authentication are defined in IETF RFC 2617. Other schemes for authentication can be supported by the HttpCredentialsHeaderValue class.

Token Token Token Token Token

Gets the user token information used in the Authorization or Proxy-Authorization HTTP header.

public : Platform::String Token { get; }
winrt::hstring Token();
public string Token { get; }
Public ReadOnly Property Token As string
var string = httpCredentialsHeaderValue.token;
Value
string string string

The user token information in the Authorization or Proxy-Authorization HTTP header.

Remarks

The Token property gets a simple string with the credentials containing the authentication information of the user agent for the resource being requested.

An HttpCredentialsHeaderValue object has a Scheme and either a Token or a Parameters list. So either the Parameters property is an empty collection or the Token property is an empty string.

Methods

Parse(String) Parse(String) Parse(String) Parse(String) Parse(String)

Converts a string to an HttpCredentialsHeaderValue instance.

public : static HttpCredentialsHeaderValue Parse(Platform::String input)
HttpCredentialsHeaderValue Parse(winrt::hstring input) const;
public static HttpCredentialsHeaderValue Parse(String input)
Public Static Function Parse(input As String) As HttpCredentialsHeaderValue
var httpCredentialsHeaderValue = Windows.Web.Http.Headers.HttpCredentialsHeaderValue.parse(input);
Parameters
input
String String String

A string that represents the credential information in the Authorization or Proxy-Authorization HTTP header.

Returns

Remarks

Below are the exceptions that this function throws.

E_INVALIDARG

The input parameter is null (Nothing in Visual Basic).

The input parameter is not valid credential information.

ToString() ToString() ToString() ToString() ToString()

Returns a string that represents the current HttpCredentialsHeaderValue object.

public : Platform::String ToString()
winrt::hstring ToString() const;
public string ToString()
Public Function ToString() As string
var string = httpCredentialsHeaderValue.toString();
Returns
string string string

A string that represents the current object.

TryParse(String, HttpCredentialsHeaderValue) TryParse(String, HttpCredentialsHeaderValue) TryParse(String, HttpCredentialsHeaderValue) TryParse(String, HttpCredentialsHeaderValue) TryParse(String, HttpCredentialsHeaderValue)

Determines whether a string is valid HttpCredentialsHeaderValue information.

public : static Platform::Boolean TryParse(Platform::String input, HttpCredentialsHeaderValue credentialsHeaderValue)
bool TryParse(winrt::hstring input, HttpCredentialsHeaderValue credentialsHeaderValue) const;
public static bool TryParse(String input, HttpCredentialsHeaderValue credentialsHeaderValue)
Public Static Function TryParse(input As String, credentialsHeaderValue As HttpCredentialsHeaderValue) As bool
var bool = Windows.Web.Http.Headers.HttpCredentialsHeaderValue.tryParse(input, credentialsHeaderValue);
Parameters
input
String String String

The string to validate.

Returns
bool bool bool

true if input is valid HttpCredentialsHeaderValue information; otherwise, false.