Export (0) Print
Expand All

HttpListenerResponse.Headers Property

Gets or sets the collection of header name/value pairs returned by the server.

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

'Declaration
Public Property Headers As WebHeaderCollection

Property Value

Type: System.Net.WebHeaderCollection
A WebHeaderCollection instance that contains all the explicitly set HTTP headers to be included in the response.

ExceptionCondition
InvalidOperationException

The WebHeaderCollection instance specified for a set operation is not valid for a response.

Response headers contain metadata information such as the date and time of the response, the identity of the responding server, and the MIME type of the data contained in the response body.

For a complete list of response headers, see the HttpResponseHeader enumeration.

NoteNote

If you attempt to set a Content-Length, Keep-Alive, Transfer-Encoding, or WWW-Authenticate header using the Headers property, an exception will be thrown. Use the KeepAlive or ContentLength64 properties to set these headers. You cannot set the Transfer-Encoding or WWW-Authenticate headers manually.

The following code example demonstrates displaying the headers in a WebHeaderCollection.


' Displays the header information that accompanied a request.
Public Shared Sub DisplayWebHeaderCollection(ByVal response As HttpListenerResponse)
    Dim headers As WebHeaderCollection = response.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
        Else
            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.

Community Additions

ADD
Show:
© 2014 Microsoft