HttpListenerRequest.Headers Property

Definition

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

Property Value

NameValueCollection

WebHeaderCollection contenant les en-têtes HTTP compris dans la demande.A WebHeaderCollection that contains the HTTP headers included in the request.

Examples

L’exemple de code suivant affiche toutes les informations contenues dans un objet WebHeaderCollection donné.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

Remarks

Les 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 le Uniform Resource Identifier (URI) de la ressource qui a renvoyé le client au serveur, l’identité de l’agent utilisateur employé par le client et les types MIME acceptables pour les données dans le corps de la 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 la liste complète des en-têtes de requête, consultez l’énumération HttpRequestHeader.For a complete list of request headers, see the HttpRequestHeader enumeration.

Applies to

See also