HttpCredentialsHeaderValue Kelas

Definisi

Mewakili nilai header HTTP Otorisasi atau Otorisasi Proksi pada permintaan 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
Warisan
Object Platform::Object IInspectable HttpCredentialsHeaderValue
Atribut
Penerapan

Persyaratan Windows

Rangkaian perangkat
Windows 10 (diperkenalkan dalam 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v1.0)

Contoh

Kode sampel berikut menunjukkan metode untuk mendapatkan dan mengatur header HTTP Otorisasi pada objek HttpRequestMessage menggunakan properti dan metode pada kelas 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());
        }

Contoh kode berikut menunjukkan metode untuk mendapatkan dan mengatur header HTTP Proxy-Authorization pada objek HttpRequestMessage menggunakan properti dan metode pada kelas 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());
        }

Keterangan

Kelas HttpCredentialsHeaderValue mewakili header HTTP Otorisasi atau Otorisasi Proksi pada permintaan HTTP.

Properti Otorisasi pada HttpRequestHeaderCollection mengembalikan objek HttpCredentialsHeaderValue yang mewakili header HTTP Otorisasi . Properti ProxyAuthorization pada HttpRequestHeaderCollection mengembalikan objek HttpCredentialsHeaderValue yang mewakili header HTTP Proxy-Authorization .

Konstruktor

HttpCredentialsHeaderValue(String)

Menginisialisasi instans baru kelas HttpCredentialsHeaderValue dengan skema yang akan digunakan untuk autentikasi.

HttpCredentialsHeaderValue(String, String)

Menginisialisasi instans baru kelas HttpCredentialsHeaderValue dengan skema dan informasi token pengguna untuk digunakan untuk autentikasi.

Properti

Parameters

Mendapatkan sekumpulan pasangan nama/nilai yang disertakan dalam header HTTP Otorisasi atau Otorisasi Proksi .

Scheme

Mendapatkan skema yang akan digunakan untuk autentikasi.

Token

Mendapatkan informasi token pengguna yang digunakan di header HTTP Otorisasi atau Otorisasi Proksi .

Metode

Parse(String)

Mengonversi string menjadi instans HttpCredentialsHeaderValue .

ToString()

Mengembalikan string yang mewakili objek HttpCredentialsHeaderValue saat ini.

TryParse(String, HttpCredentialsHeaderValue)

Menentukan apakah string adalah informasi HttpCredentialsHeaderValue yang valid.

Berlaku untuk

Lihat juga