This documentation is archived and is not being maintained.

HttpListenerRequest.Headers Property

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

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 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 value
            Console.WriteLine("There is no value associated with the header.")
        End If
    Next key
End Sub

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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