WebClient.ResponseHeaders Property

Definition

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

C#
public System.Net.WebHeaderCollection? ResponseHeaders { get; }
C#
public System.Net.WebHeaderCollection ResponseHeaders { get; }

Property Value

A WebHeaderCollection containing header name/value pairs associated with the response, or null if no response has been received.

Examples

The following code example downloads and displays the ResponseHeaders returned by a server.

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));

Remarks

Výstraha

WebRequest, HttpWebRequest, ServicePoint, and WebClient are obsolete, and you shouldn't use them for new development. Use HttpClient instead.

The ResponseHeaders property contains a WebHeaderCollection instance containing header information the WebClient receives with the response.

Applies to

Produkt Verzie
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1