HttpListenerRequest.Headers HttpListenerRequest.Headers HttpListenerRequest.Headers HttpListenerRequest.Headers Property

Définition

Obtient la collection de paires nom/valeur d’en-tête envoyées dans la demande.Gets the collection of header name/value pairs sent in the request.

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

Valeur de propriété

Un WebHeaderCollection qui contient les en-têtes HTTP inclus dans la demande.A WebHeaderCollection that contains the HTTP headers included in the request.

Exemples

L’exemple de code suivant affiche les informations contenues dans une donnée WebHeaderCollection objet.The following code example displays all the information in a given WebHeaderCollection object.

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

Remarques

En-têtes de requête contiennent des informations de métadonnées.Request headers contain metadata information. Par exemple, les en-têtes peuvent contenir l’identificateur URI (Uniform Resource) de la ressource qui a signalé le client au serveur, l’identité de l’agent utilisateur employées par le client et le MIME acceptable, les types de données dans le corps de réponse.For example, headers can contain the Uniform Resource Identifier (URI) of the resource that referred the client to the server, the identity of the user agent employed by the client, and the acceptable MIME types for data in the response body.

Pour obtenir une liste complète des en-têtes de demande, consultez le HttpRequestHeader énumération.For a complete list of request headers, see the HttpRequestHeader enumeration.

S’applique à

Voir aussi