HttpCredentialsHeaderValue Classe

Définition

Représente la valeur de l’en-tête HTTP Authorization ou Proxy-Authorization sur une requête HTTP.

public ref class HttpCredentialsHeaderValue sealed : IStringable
/// [Windows.Foundation.Metadata.Activatable(Windows.Web.Http.Headers.IHttpCredentialsHeaderValueFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class HttpCredentialsHeaderValue final : IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Web.Http.Headers.IHttpCredentialsHeaderValueFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class HttpCredentialsHeaderValue final : IStringable
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Web.Http.Headers.IHttpCredentialsHeaderValueFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class HttpCredentialsHeaderValue : IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Web.Http.Headers.IHttpCredentialsHeaderValueFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class HttpCredentialsHeaderValue : IStringable
function HttpCredentialsHeaderValue(scheme, token)
Public NotInheritable Class HttpCredentialsHeaderValue
Implements IStringable
Héritage
Object Platform::Object IInspectable HttpCredentialsHeaderValue
Attributs
Implémente

Configuration requise pour Windows

Famille d’appareils
Windows 10 (introduit dans 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v1.0)

Exemples

L’exemple de code suivant montre une méthode permettant d’obtenir et de définir l’en-tête HTTP Authorization sur un objet HttpRequestMessage à l’aide des propriétés et des méthodes de la classe HttpCredentialsHeaderValue.

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

L’exemple de code suivant montre une méthode permettant d’obtenir et de définir l’en-tête HTTP Proxy-Authorization sur un objet HttpRequestMessage à l’aide des propriétés et des méthodes de la classe HttpCredentialsHeaderValue.

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

Remarques

La classe HttpCredentialsHeaderValue représente l’en-tête HTTP Authorization ou Proxy-Authorization sur une requête HTTP.

La propriété Authorization sur httpRequestHeaderCollection renvoie un objet HttpCredentialsHeaderValue qui représente l’en-tête HTTP Authorization . La propriété ProxyAuthorization sur httpRequestHeaderCollection renvoie un objet HttpCredentialsHeaderValue qui représente l’en-tête HTTP Proxy-Authorization .

Constructeurs

HttpCredentialsHeaderValue(String)

Initialise une nouvelle instance de la classe HttpCredentialsHeaderValue avec le schéma à utiliser pour l’authentification.

HttpCredentialsHeaderValue(String, String)

Initialise une nouvelle instance de la classe HttpCredentialsHeaderValue avec les informations de schéma et de jeton utilisateur à utiliser pour l’authentification.

Propriétés

Parameters

Obtient un ensemble de paires nom/valeur inclus dans l’en-tête HTTP Authorization ou Proxy-Authorization .

Scheme

Obtient le schéma à utiliser pour l’authentification.

Token

Obtient les informations de jeton utilisateur utilisées dans l’en-tête HTTP Autorisation ou Proxy-Authorization .

Méthodes

Parse(String)

Convertit une chaîne en instance HttpCredentialsHeaderValue.

ToString()

Renvoie une chaîne qui représente l’objet HttpCredentialsHeaderValue actuel.

TryParse(String, HttpCredentialsHeaderValue)

Détermine si une chaîne est des informations HttpCredentialsHeaderValue valides .

S’applique à

Voir aussi