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.

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.

Properties

Parameters Parameters Parameters Parameters Parameters

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

Scheme Scheme Scheme Scheme Scheme

Gets the scheme to use for authentication.

Token Token Token Token Token

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

Methods

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

Converts a string to an HttpCredentialsHeaderValue instance.

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

Returns a string that represents the current HttpCredentialsHeaderValue object.

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

Determines whether a string is valid HttpCredentialsHeaderValue information.

See Also