WebClient.ResponseHeaders Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a collection of header name/value pairs associated with the response.
public:
property System::Net::WebHeaderCollection ^ ResponseHeaders { System::Net::WebHeaderCollection ^ get(); };
public System.Net.WebHeaderCollection? ResponseHeaders { get; }
public System.Net.WebHeaderCollection ResponseHeaders { get; }
member this.ResponseHeaders : System.Net.WebHeaderCollection
Public ReadOnly Property ResponseHeaders As WebHeaderCollection
A WebHeaderCollection containing header name/value pairs associated with the response, or null
if no response has been received.
The following code example downloads and displays the ResponseHeaders returned by a server.
// 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{0} = {1}", myWebHeaderCollection->GetKey( i ),
myWebHeaderCollection->Get( i ) );
}
// 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));
' 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
Forsiktig
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.
Produkt | Versjoner |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.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 |
.NET-tilbakemelding
.NET er et åpen kilde-prosjekt. Velg en kobling for å gi tilbakemelding: