Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HttpCredentialsHeaderValue class

Applies to Windows and Windows Phone

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

Syntax


public ref class HttpCredentialsHeaderValue sealed : IStringable

Attributes

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06030000)]

Members

The HttpCredentialsHeaderValue class has these types of members:

Constructors

The HttpCredentialsHeaderValue class has these constructors.

ConstructorDescription
HttpCredentialsHeaderValue(String) Initializes a new instance of the HttpCredentialsHeaderValue class with the scheme to use for authentication.
HttpCredentialsHeaderValue(String, String) Initializes a new instance of the HttpCredentialsHeaderValue class with the scheme and user token information to use for authentication.

 

Methods

The HttpCredentialsHeaderValue class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
Parse Converts a string to an HttpCredentialsHeaderValue instance.
ToString Returns a string that represents the current HttpCredentialsHeaderValue object.
TryParse Determines whether a string is valid HttpCredentialsHeaderValue information.

 

Properties

The HttpCredentialsHeaderValue class has these properties.

PropertyAccess typeDescription

Parameters

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

Scheme

Read-onlyGets the scheme to use for authentication.

Token

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

 

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.

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());
        }


Requirements

Minimum supported client

Windows 8.1 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 R2 [Windows Store apps, desktop apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Web.Http.Headers
Windows::Web::Http::Headers [C++]

Metadata

Windows.winmd

See also

Authorization
HttpRequestHeaderCollection
IStringable
Object
ProxyAuthorization

 

 

Show:
© 2014 Microsoft. All rights reserved.