Export (0) Print
Expand All

HttpListenerRequest.Headers Property

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

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

'Declaration
Public ReadOnly Property Headers As NameValueCollection

Property Value

Type: System.Collections.Specialized.NameValueCollection
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);
            }
        }
        else
            Console.WriteLine("There is no value associated with the header.");
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft