Export (0) Print
Expand All

HttpWebResponse.Headers Property

Gets the headers that are associated with this response from the server.

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

'Declaration
Public Overrides ReadOnly Property Headers As WebHeaderCollection

Property Value

Type: System.Net.WebHeaderCollection
A WebHeaderCollection that contains the header information returned with the response.

ExceptionCondition
ObjectDisposedException

The current instance has been disposed.

The Headers property is a collection of name/value pairs that contain the HTTP header values returned with the response. Common header information returned from the Internet resource is exposed as properties of the HttpWebResponse class. The following table lists common headers that the API exposes as properties.

Header

Property

Content-Encoding

ContentEncoding

Content-Length

ContentLength

Content-Type

ContentType

Last-Modified

LastModified

Server

Server

The following example writes the contents of all of the response headers to the console.

            ' Creates an HttpWebRequest with the specified URL.  
            Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
            ' Sends the HttpWebRequest and waits for a response. 
            Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
            ' Displays all the Headers present in the response received from the URI.
            Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "The following headers were received in the response")
            'The Headers property is a WebHeaderCollection. Use it's properties to traverse the collection and display each header. 
            Dim i As Integer 
            While i < myHttpWebResponse.Headers.Count
                Console.WriteLine(ControlChars.Cr + "Header Name:{0}, Value :{1}", myHttpWebResponse.Headers.Keys(i), myHttpWebResponse.Headers(i))
		      i = i + 1
            End While
            myHttpWebResponse.Close()

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, 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