HttpListenerRequest.Headers Property

Note: This property is new in the .NET Framework version 2.0.

Gets the collection of header name/value pairs sent in the request.

Namespace: System.Net
Assembly: System (in system.dll)

Public ReadOnly Property Headers As NameValueCollection
Dim instance As HttpListenerRequest
Dim value As NameValueCollection

value = instance.Headers

/** @property */
public NameValueCollection get_Headers ()

public function get Headers () : NameValueCollection

Property Value

A WebHeaderCollection that contains the HTTP headers included in the request.

Request headers contain metadata information. 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.

For a complete list of request headers, see the HttpRequestHeader enumeration.

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);
            Console.WriteLine("There is no value associated with the header.");

Windows 98, Windows Server 2003, Windows XP Media Center Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions