Bagikan melalui


HttpListenerRequest.Headers Properti

Definisi

Mendapatkan kumpulan pasangan nama/nilai header yang dikirim dalam permintaan.

public:
 property System::Collections::Specialized::NameValueCollection ^ Headers { System::Collections::Specialized::NameValueCollection ^ get(); };
public System.Collections.Specialized.NameValueCollection Headers { get; }
member this.Headers : System.Collections.Specialized.NameValueCollection
Public ReadOnly Property Headers As NameValueCollection

Nilai Properti

WebHeaderCollection yang berisi header HTTP yang disertakan dalam permintaan.

Contoh

Contoh kode berikut menampilkan semua informasi dalam objek tertentu WebHeaderCollection .

    // Displays the header information that accompanied a request.
public static void DisplayWebHeaderCollection(HttpListenerRequest request)
{
    System.Collections.Specialized.NameValueCollection headers = request.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.");
        }
    }
}
Public Shared Sub DisplayWebHeaderCollection(ByVal request As HttpListenerRequest)
    Dim headers As System.Collections.Specialized.NameValueCollection = request.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 permintaan berisi informasi metadata. Misalnya, header dapat berisi Pengidentifikasi Sumber Daya Seragam (URI) sumber daya yang merujuk klien ke server, identitas agen pengguna yang digunakan oleh klien, dan jenis MIME yang dapat diterima untuk data dalam isi respons.

Untuk daftar lengkap header permintaan, lihat HttpRequestHeader enumerasi.

Berlaku untuk

Lihat juga