語言

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 需求

規格需求 Description
裝置系列
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具有建構函式,而且也會由HttpBufferContent、HttpFormUrlEncodedContent、HttpMultipartContent、HttpMultipartFormDataContent、HttpStreamContent和HttpStringContent、類別和IHttpContent介面上的 屬性傳回。

列舉 C# 或 Microsoft Visual Basic 中的集合

您可以在 C# 或 Microsoft Visual Basic 中逐一查看 HttpContentHeaderCollection 物件。 在許多情況下,例如使用 foreach 語法,編譯器會為您執行此轉換,而且您不需要明確地轉換成 IEnumerable 。 如果您需要明確轉換,例如,如果您想要呼叫GetEnumerator,請將集合物件轉換成具有String和String的 KeyValuePair 作為條件約束的IEnumerable < T >。

建構函式

名稱 Description
HttpContentHeaderCollection()

初始化 HttpContentHeaderCollection 類別的新實例。

屬性

名稱 Description
ContentDisposition

取得或設定 HttpContentDispositionHeaderValue 物件,代表 HTTP 內容上 HTTP Content-Disposition 標頭的值。

ContentEncoding

取得 HttpContentCodingHeaderValueCollection 的 HttpContentCodingHeaderValue 物件,這些物件代表 HTTP 內容上 HTTP Content-Encoding 標頭的值。

ContentLanguage

取得 物件的 HttpLanguageHeaderValueCollection ,這些物件代表 HTTP 內容上 HTTP Content-Language 標頭的值。

ContentLength

取得或設定 HTTP 內容上 HTTP Content-Length 標頭的值。

ContentLocation

取得或設定 HTTP 內容上 HTTP Content-Location 標頭的值。

ContentMD5

取得或設定 HTTP 內容上 HTTP Content-MD5 標頭的值。

ContentRange

取得或設定 HttpContentRangeHeaderValue 物件,代表 HTTP 內容上 HTTP Content-Range 標頭的值。

ContentType

取得或設定 HttpMediaTypeHeaderValue 物件,代表 HTTP 內容上 HTTP Content-Type 標頭的值。

Expires

取得或設定 DateTime 物件,表示 HTTP 內容上 HTTP Expires 標頭的值。

LastModified

取得或設定 DateTime 物件,表示 HTTP 內容上 HTTP Last-Modified 標頭的值。

Size

取得 HttpContentHeaderCollection中的物件數目。

方法

名稱 Description
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 ,而不需驗證。

適用於

另請參閱