HttpListenerRequest.Headers Proprietà

Definizione

Ottiene un insieme delle coppie nome/valore di intestazione inviate nella risposta.

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

Valore della proprietà

Classe WebHeaderCollection contenente le intestazioni HTTP incluse nella richiesta.

Esempio

Nell'esempio di codice seguente vengono visualizzate tutte le informazioni in un determinato WebHeaderCollection oggetto.

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

Commenti

Le intestazioni di richiesta contengono informazioni sui metadati. Ad esempio, le intestazioni possono contenere l'URI (Uniform Resource Identifier) della risorsa che ha fatto riferimento al client al server, l'identità dell'agente utente usata dal client e i tipi MIME accettabili per i dati nel corpo della risposta.

Per un elenco completo di intestazioni di richiesta, vedere l'enumerazione HttpRequestHeader .

Si applica a

Vedi anche