Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

WebClient.ResponseHeaders Property

Gets a collection of header name/value pairs associated with the response.

[Visual Basic]
Public ReadOnly Property ResponseHeaders As WebHeaderCollection
[C#]
public WebHeaderCollection ResponseHeaders {get;}
[C++]
public: __property WebHeaderCollection* get_ResponseHeaders();
[JScript]
public function get ResponseHeaders() : WebHeaderCollection;

Property Value

A WebHeaderCollection containing header name/value pairs associated with this response.

Remarks

The ResponseHeaders property contains a WebHeaderCollection instance containing header information the WebClient receives from the Internet resource.

Example

[Visual Basic, C#, C++] The following example downloads and displays the ResponseHeaders returned by a server.

[Visual Basic] 
' ResponseHeaders is a WebHeaderCollection instance that contains the headers sent back 
 ' in response to the WebClient request. 
Dim myWebHeaderCollection As WebHeaderCollection = myWebClient.ResponseHeaders
Console.WriteLine(ControlChars.Cr + "Displaying the response headers" + ControlChars.Cr)
' Loop through the ResponseHeaders.
Dim i As Integer
For i = 0 To myWebHeaderCollection.Count - 1
    ' Display the headers as name/value pairs.
    Console.WriteLine((ControlChars.Tab + myWebHeaderCollection.GetKey(i) + " " + ChrW(61) + " " + myWebHeaderCollection.Get(i)))
Next i 

[C#] 
// Obtain the WebHeaderCollection instance containing the header name/value pair from the response.
WebHeaderCollection myWebHeaderCollection = myWebClient.ResponseHeaders;
Console.WriteLine("\nDisplaying the response headers\n");
// Loop through the ResponseHeaders and display the header name/value pairs.
for (int i=0; i < myWebHeaderCollection.Count; i++)                
    Console.WriteLine ("\t" + myWebHeaderCollection.GetKey(i) + " = " + myWebHeaderCollection.Get(i));

[C++] 
// Obtain the WebHeaderCollection instance containing the header name/value pair from the response.
WebHeaderCollection* myWebHeaderCollection = myWebClient->ResponseHeaders;
Console::WriteLine(S"\nDisplaying the response headers\n");
// Loop through the ResponseHeaders and display the header name/value pairs.
for (int i = 0; i < myWebHeaderCollection->Count; i++)
   Console::WriteLine (S"\t {0} = {1}", myWebHeaderCollection->GetKey(i), myWebHeaderCollection->Get(i));

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

WebClient Class | WebClient Members | System.Net Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.