HttpListenerResponse.Headers プロパティ

定義

サーバーから返されるヘッダーの名前と値のペアのコレクションを取得または設定します。

public:
 property System::Net::WebHeaderCollection ^ Headers { System::Net::WebHeaderCollection ^ get(); void set(System::Net::WebHeaderCollection ^ value); };
public System.Net.WebHeaderCollection Headers { get; set; }
member this.Headers : System.Net.WebHeaderCollection with get, set
Public Property Headers As WebHeaderCollection

プロパティ値

WebHeaderCollection

応答に挿入される、明示的に設定されたすべての HTTP ヘッダーを格納している WebHeaderCollection インスタンス。

例外

設定操作に指定された WebHeaderCollection インスタンスが、応答では無効です。

次のコード例では、ヘッダー WebHeaderCollectionを .

    // Displays the header information that accompanied a request.
public static void DisplayWebHeaderCollection(HttpListenerResponse response)
{
    WebHeaderCollection headers = response.Headers;
    // Get each header and display each value.
    foreach (string key in headers.AllKeys)
    {
        string[] values = headers.GetValues(key);
        if(values.Length > 0)
        {
            Console.WriteLine("The values of the {0} header are: ", key);
            foreach (string value in values)
            {
                Console.WriteLine("   {0}", value);
            }
        }
        else
        {
            Console.WriteLine("There is no value associated with the header.");
        }
    }
}
' Displays the header information that accompanied a request.
Public Shared Sub DisplayWebHeaderCollection(ByVal response As HttpListenerResponse)
    Dim headers As WebHeaderCollection = response.Headers

    ' Get each header and display each value.
    For Each key As String In headers.AllKeys
        Dim values As String() = headers.GetValues(key)

        If values.Length > 0 Then
            Console.WriteLine("The values of the {0} header are: ", key)

            For Each value As String In values
                Console.WriteLine("   {0}", value)
            Next
        Else
            Console.WriteLine("There is no value associated with the header.")
        End If
    Next
End Sub

注釈

応答ヘッダーには、応答の日時、応答サーバーの ID、応答本文に含まれるデータの MIME の種類などのメタデータ情報が含まれています。

応答ヘッダーの完全な一覧については、列挙型を HttpResponseHeader 参照してください。

注意

Headers プロパティを使用して Content-Length、Keep-Alive、Transfer-Encoding、または WWW-Authenticate ヘッダーを設定しようとすると、例外がスローされます。 これらのヘッダーを設定するには、 KeepAlive プロパティを ContentLength64 使用します。 Transfer-EncodingまたはWWW-Authenticateヘッダーを手動で設定することはできません。

適用対象

こちらもご覧ください