HttpCredentialsHeaderValue クラス

定義

HTTP 要求の Authorization または Proxy-Authorization 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
継承
Object Platform::Object IInspectable HttpCredentialsHeaderValue
属性
実装

Windows の要件

デバイス ファミリ
Windows 10 (10.0.10240.0 で導入)
API contract
Windows.Foundation.UniversalApiContract (v1.0 で導入)

次のサンプル コードは、HttpCredentialsHeaderValue クラスのプロパティとメソッドを使用して、HttpRequestMessage オブジェクトの Authorization HTTP ヘッダーを取得および設定するメソッドを示しています。

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

次のサンプル コードは、HttpCredentialsHeaderValue クラスのプロパティとメソッドを使用して、HttpRequestMessage オブジェクトの Proxy-Authorization HTTP ヘッダーを取得および設定するメソッドを示しています。

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

注釈

HttpCredentialsHeaderValue クラスは、HTTP 要求の Authorization または Proxy-Authorization HTTP ヘッダーを表します。

HttpRequestHeaderCollectionAuthorization プロパティは、Authorization HTTP ヘッダーを表す HttpCredentialsHeaderValue オブジェクトを返します。 HttpRequestHeaderCollectionProxyAuthorization プロパティは、Proxy-Authorization HTTP ヘッダーを表す HttpCredentialsHeaderValue オブジェクトを返します。

コンストラクター

HttpCredentialsHeaderValue(String)

認証に使用するスキームを使用して 、HttpCredentialsHeaderValue クラスの新しいインスタンスを初期化します。

HttpCredentialsHeaderValue(String, String)

認証に使用するスキームとユーザー トークン情報を使用して 、HttpCredentialsHeaderValue クラスの新しいインスタンスを初期化します。

プロパティ

Parameters

Authorization または Proxy-Authorization HTTP ヘッダーに含まれる一連の名前と値のペアを取得します。

Scheme

認証に使用するスキームを取得します。

Token

Authorization または Proxy-Authorization HTTP ヘッダーで使用されるユーザー トークン情報を取得します。

メソッド

Parse(String)

文字列を HttpCredentialsHeaderValue インスタンスに 変換します。

ToString()

現在の HttpCredentialsHeaderValue オブジェクトを表す文字列を返します。

TryParse(String, HttpCredentialsHeaderValue)

文字列が有効な HttpCredentialsHeaderValue 情報であるかどうかを判断します。

適用対象

こちらもご覧ください