HttpCredentialsHeaderValue Klasse

Definition

Stellt den Wert des HTTP-Headers Authorization oder Proxy-Authorization für eine HTTP-Anforderung dar.

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
Vererbung
Object Platform::Object IInspectable HttpCredentialsHeaderValue
Attribute
Implementiert

Windows-Anforderungen

Gerätefamilie
Windows 10 (eingeführt in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (eingeführt in v1.0)

Beispiele

Der folgende Beispielcode zeigt eine Methode zum Abrufen und Festlegen des Autorisierungs-HTTP-Headers für ein HttpRequestMessage-Objekt mithilfe der Eigenschaften und Methoden der HttpCredentialsHeaderValue-Klasse.

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

Der folgende Beispielcode zeigt eine Methode zum Abrufen und Festlegen des Proxy-Authorization-HTTP-Headers für ein HttpRequestMessage-Objekt mithilfe der Eigenschaften und Methoden der HttpCredentialsHeaderValue-Klasse.

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

Hinweise

Die HttpCredentialsHeaderValue-Klasse stellt den AUTHORIZATION- oder Proxy-Authorization-HTTP-Header für eine HTTP-Anforderung dar.

Die Authorization-Eigenschaft für httpRequestHeaderCollection gibt ein HttpCredentialsHeaderValue-Objekt zurück, das den Authorization-HTTP-Header darstellt. Die ProxyAuthorization-Eigenschaft für httpRequestHeaderCollection gibt ein HttpCredentialsHeaderValue-Objekt zurück, das den PROXY-Authorization-HTTP-Header darstellt.

Konstruktoren

HttpCredentialsHeaderValue(String)

Initialisiert eine neue instance der HttpCredentialsHeaderValue-Klasse mit dem Schema, das für die Authentifizierung verwendet werden soll.

HttpCredentialsHeaderValue(String, String)

Initialisiert eine neue instance der HttpCredentialsHeaderValue-Klasse mit den Schema- und Benutzertokeninformationen, die für die Authentifizierung verwendet werden sollen.

Eigenschaften

Parameters

Ruft einen Satz von Name-Wert-Paaren ab, die im HTTP-Header Authorization oder Proxy-Authorization enthalten sind.

Scheme

Ruft das schema ab, das für die Authentifizierung verwendet werden soll.

Token

Ruft die Benutzertokeninformationen ab, die im HTTP-Header Authorization oder Proxy-Authorization verwendet werden.

Methoden

Parse(String)

Konvertiert eine Zeichenfolge in eine HttpCredentialsHeaderValue-instance.

ToString()

Gibt eine Zeichenfolge zurück, die das aktuelle HttpCredentialsHeaderValue-Objekt darstellt.

TryParse(String, HttpCredentialsHeaderValue)

Bestimmt, ob eine Zeichenfolge gültige HttpCredentialsHeaderValue-Informationen ist.

Gilt für:

Weitere Informationen