HttpListenerRequest.Headers Vlastnost

Definice

Získá kolekci dvojic název/hodnota hlavičky odeslané v požadavku.

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

Hodnota vlastnosti

A WebHeaderCollection , který obsahuje hlavičky HTTP zahrnuté v požadavku.

Příklady

Následující příklad kódu zobrazí všechny informace v daném WebHeaderCollection objektu.

    // 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

Poznámky

Hlavičky požadavku obsahují informace o metadatech. Hlavičky můžou například obsahovat identifikátor URI prostředku, který odkazoval klienta na server, identitu uživatelského agenta používaného klientem a přijatelné typy MIME pro data v textu odpovědi.

Úplný seznam hlaviček požadavků najdete ve výčtu HttpRequestHeader .

Platí pro

Viz také