Share via


HttpListenerResponse.Headers Properti

Definisi

Mendapatkan atau mengatur kumpulan pasangan nama/nilai header yang dikembalikan oleh server.

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

Nilai Properti

WebHeaderCollection Instans yang berisi semua header HTTP yang diatur secara eksplisit untuk disertakan dalam respons.

Pengecualian

WebHeaderCollection Instans yang ditentukan untuk operasi set tidak valid untuk respons.

Contoh

Contoh kode berikut menunjukkan menampilkan header dalam 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

Keterangan

Header respons berisi informasi metadata seperti tanggal dan waktu respons, identitas server yang merespons, dan jenis DATA MIME yang terkandung dalam isi respons.

Untuk daftar lengkap header respons, lihat HttpResponseHeader enumerasi.

Catatan

Jika Anda mencoba mengatur header Content-Length, Keep-Alive, Transfer-Encoding, atau WWW-Authenticate menggunakan properti Header, pengecualian akan dilemparkan. KeepAlive Gunakan properti atau ContentLength64 untuk mengatur header ini. Anda tidak dapat mengatur header Transfer-Encoding atau WWW-Authenticate secara manual.

Berlaku untuk

Lihat juga