Share via


HttpContentHeaderCollection クラス

定義

HTTP 要求または応答のコンテンツに関連付けられている HTTP ヘッダーのコレクションを提供します。

public ref class HttpContentHeaderCollection sealed : IIterable<IKeyValuePair<Platform::String ^, Platform::String ^> ^>, IMap<Platform::String ^, Platform::String ^>, IStringable
/// [Windows.Foundation.Metadata.Activatable(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 HttpContentHeaderCollection final : IIterable<IKeyValuePair<winrt::hstring, winrt::hstring const&>>, IMap<winrt::hstring, winrt::hstring const&>, 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(65536, "Windows.Foundation.UniversalApiContract")]
class HttpContentHeaderCollection final : IIterable<IKeyValuePair<winrt::hstring, winrt::hstring const&>>, IMap<winrt::hstring, winrt::hstring const&>, IStringable
[Windows.Foundation.Metadata.Activatable(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 HttpContentHeaderCollection : IDictionary<string,string>, IEnumerable<KeyValuePair<string,string>>, 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(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class HttpContentHeaderCollection : IDictionary<string,string>, IEnumerable<KeyValuePair<string,string>>, IStringable
function HttpContentHeaderCollection()
Public NotInheritable Class HttpContentHeaderCollection
Implements IDictionary(Of String, String), IEnumerable(Of KeyValuePair(Of String, String)), IStringable
継承
Object Platform::Object IInspectable HttpContentHeaderCollection
属性
実装
IMap<String,String> IDictionary<String,String> IMap<Platform::String,Platform::String> IMap<winrt::hstring,winrt::hstring> IIterable<IKeyValuePair<K,V>> IEnumerable<KeyValuePair<K,V>> IIterable<IKeyValuePair<String,String>> IEnumerable<KeyValuePair<String,String>> IIterable<IKeyValuePair<Platform::String,Platform::String>> IIterable<IKeyValuePair<winrt::hstring,winrt::hstring>> IStringable

Windows の要件

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

次のサンプル コードは、 HttpContentHeaderCollection オブジェクトのプロパティを使用して HTTP コンテンツのヘッダーを取得および設定するメソッドを示しています。 Windows.Web.Http.Headers 名前空間には、検証でヘッダーを取得および設定するために使用できる特定の HTTP ヘッダーに対して、厳密に型指定されたヘッダー コレクションと値クラスが多数用意されています。

using System;
using Windows.Web.Http;
using Windows.Web.Http.Headers;

public void DemonstrateContentHeader()
{
    DemonstrateHeaderContentContentDisposition();
}

public void DemonstrateHeaderContentContentDisposition()
{
    var content = new HttpStringContent("");
    bool parsedOk = false;

    // Set the header with a string.
    HttpContentDispositionHeaderValue value;
    parsedOk = HttpContentDispositionHeaderValue.TryParse("attachment; filename=\"fname.ext\"", out value);
    content.Headers.ContentDisposition = value;

    // Set the header with a strong type.

    content.Headers.ContentDisposition = new HttpContentDispositionHeaderValue("attachment");
    content.Headers.ContentDisposition.FileName = "myfile.exe";


    // Get the strong type out
    System.Diagnostics.Debug.WriteLine("ContentDisposition filename: {0}={1}",
        content.Headers.ContentDisposition.DispositionType,
        content.Headers.ContentDisposition.FileName);

    // The ToString() is useful for diagnostics, too.
    System.Diagnostics.Debug.WriteLine("The ContentDisposition ToString() results: {0}", content.Headers.ContentDisposition.ToString());
}

注釈

HttpContentHeaderCollection は、HTTP 要求または HTTP 応答メッセージの HTTP コンテンツに関連付けられている HTTP ヘッダーのコレクションです。 HttpContentHeaderCollection オブジェクトを使用して、HTTP コンテンツの特定のヘッダーを取得または設定できます。 HttpContentHeaderCollection オブジェクトのほとんどのプロパティは、特定の HTTP ヘッダーのコンテナー コレクションへのアクセスを提供します。

HttpContentHeaderCollection にはコンストラクターがあり、HttpBufferContentHttpFormUrlEncodedContent、HttpMultipartContentHttpMultipartFormDataContentHttpStreamContentHttpStringContent、クラス、および IHttpContent インターフェイスの プロパティによっても返されます。

C# または Microsoft Visual Basic でのコレクションの列挙

C# または Microsoft Visual Basic で HttpContentHeaderCollection オブジェクトを反復処理できます。 foreach 構文の使用など、多くの場合、コンパイラによってこのキャストが行われ、明示的に キャストするIEnumerable必要はありません。 GetEnumerator を呼び出す場合など、明示的にキャストする必要がある場合は、制約として StringStringKeyValuePair を使用してコレクション オブジェクトを IEnumerable<T> にキャストします。

コンストラクター

HttpContentHeaderCollection()

HttpContentHeaderCollection クラスの新しいインスタンスを初期化します。

プロパティ

ContentDisposition

HTTP コンテンツの HTTP Content-Disposition ヘッダーの値を表す HttpContentDispositionHeaderValue オブジェクトを取得または設定します。

ContentEncoding

HTTP コンテンツの HTTP Content-Encoding ヘッダーの値を表す HttpContentCodingHeaderValue オブジェクトの HttpContentCodingHeaderValueCollection を取得します。

ContentLanguage

HTTP コンテンツの HTTP Content-Language ヘッダーの値を表すオブジェクトの HttpLanguageHeaderValueCollection を取得します。

ContentLength

HTTP コンテンツの HTTP Content-Length ヘッダーの値を取得または設定します。

ContentLocation

HTTP コンテンツの HTTP Content-Location ヘッダーの値を取得または設定します。

ContentMD5

HTTP コンテンツの HTTP Content-MD5 ヘッダーの値を取得または設定します。

ContentRange

HTTP コンテンツの HTTP Content-Range ヘッダーの値を表す HttpContentRangeHeaderValue オブジェクトを取得または設定します。

ContentType

HTTP コンテンツの HTTP Content-Type ヘッダーの値を表す HttpMediaTypeHeaderValue オブジェクトを取得または設定します。

Expires

HTTP コンテンツの HTTP Expires ヘッダーの値を表す DateTime オブジェクトを取得または設定します。

LastModified

HTTP コンテンツの HTTP Last-Modified ヘッダーの値を表す DateTime オブジェクトを取得または設定します。

Size

HttpContentHeaderCollection 内のオブジェクトの数を取得します。

メソッド

Append(String, String)

HttpContentHeaderCollection の末尾に新しい項目を追加します。

Clear()

HttpContentHeaderCollection からすべてのオブジェクトを削除します。

First()

HttpContentHeaderCollection の最初の項目を指す反復子を取得します。

GetView()

HttpContentHeaderCollection の変更できないビューを返します。

HasKey(String)

HttpContentHeaderCollection に指定したキーが含まれているかどうかを判断します。

Insert(String, String)

HttpContentHeaderCollection 内の項目を、指定したキーと値で挿入または置換します。

Lookup(String)

HttpContentHeaderCollection 内のアイテムが存在する場合は、そのアイテムを検索します。

Remove(String)

HttpContentHeaderCollection から特定のオブジェクトを削除します。

ToString()

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

TryAppendWithoutValidation(String, String)

検証を行わずに、指定した項目を HttpContentHeaderCollection に追加してみてください。

適用対象

こちらもご覧ください