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, IHttpCredentialsHeaderValuepublic sealed class HttpCredentialsHeaderValue : IStringable, IHttpCredentialsHeaderValuePublic NotInheritable Class HttpCredentialsHeaderValue Implements IStringable, IHttpCredentialsHeaderValue// You can use this class in JavaScript.
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)

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

public : HttpCredentialsHeaderValue(PlatForm::String scheme)public HttpCredentialsHeaderValue(String scheme)Public Sub New(scheme As String)// You can use this method in JavaScript.
Parameters
scheme
PlatForm::String String String String

The scheme to use for authentication.

See Also

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)public HttpCredentialsHeaderValue(String scheme, String token)Public Sub New(scheme As String, token As String)// You can use this method in JavaScript.
Parameters
scheme
PlatForm::String String String String

The scheme to use for authentication.

token
PlatForm::String String String String

The user token information to use for authentication.

See Also

Properties

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; }public IList<HttpNameValueHeaderValue> Parameters { get; }Public ReadOnly Property Parameters As IList<HttpNameValueHeaderValue>// You can use this property in JavaScript.
Value
IVector<HttpNameValueHeaderValue> 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

Gets the scheme to use for authentication.

public : PlatForm::String Scheme { get; }public string Scheme { get; }Public ReadOnly Property Scheme As string// You can use this property in JavaScript.
Value
PlatForm::String 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

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

public : PlatForm::String Token { get; }public string Token { get; }Public ReadOnly Property Token As string// You can use this property in JavaScript.
Value
PlatForm::String 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)

Converts a string to an HttpCredentialsHeaderValue instance.

public : static HttpCredentialsHeaderValue Parse(PlatForm::String input)public static HttpCredentialsHeaderValue Parse(String input)Public Static Function Parse(input As String) As HttpCredentialsHeaderValue// You can use this method in JavaScript.
Parameters
input
PlatForm::String 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()

Returns a string that represents the current HttpCredentialsHeaderValue object.

public : PlatForm::String ToString()public string ToString()Public Function ToString() As string// You can use this method in JavaScript.
Returns
PlatForm::String string string string

A string that represents the current object.

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)public static bool TryParse(String input, HttpCredentialsHeaderValue credentialsHeaderValue)Public Static Function TryParse(input As String, credentialsHeaderValue As HttpCredentialsHeaderValue) As bool// You can use this method in JavaScript.
Parameters
input
PlatForm::String String String String

The string to validate.

Returns
PlatForm::Boolean bool bool bool

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