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)

public:
property NameValueCollection^ Headers {
	NameValueCollection^ get ();
}

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.");
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft