HttpWebResponse.Headers-Eigenschaft
Ruft die Header ab, die dieser Antwort vom Server zugeordnet sind.
Namespace: System.Net
Assembly: System (in system.dll)
Syntax
'Declaration
Public Overrides ReadOnly Property Headers As WebHeaderCollection
'Usage
Dim instance As HttpWebResponse
Dim value As WebHeaderCollection
value = instance.Headers
public override WebHeaderCollection Headers { get; }
public:
virtual property WebHeaderCollection^ Headers {
WebHeaderCollection^ get () override;
}
/** @property */
public WebHeaderCollection get_Headers ()
public override function get Headers () : WebHeaderCollection
Eigenschaftenwert
Eine WebHeaderCollection mit den mit der Antwort zurückgegebenen Headerinformationen.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
Die aktuelle Instanz wurde bereits verworfen. |
Hinweise
Die Headers-Eigenschaft ist eine Auflistung von Name-Wert-Paaren mit den mit der Antwort zurückgegebenen HTTP-Headerwerten. Allgemeine Headerinformationen, die von der Internetressource zurückgegeben werden, werden als Eigenschaften der HttpWebResponse-Klasse verfügbar gemacht. Die folgende Tabelle enthält die häufig verwendeten Header, die von der API als Eigenschaften verfügbar gemacht werden.
Header |
Eigenschaft |
---|---|
Content-Encoding |
|
Content-Length |
|
Content-Type |
|
Last-Modified |
|
Server |
Beispiel
Im folgenden Beispiel wird der Inhalt aller Antwortheader auf der Konsole ausgegeben.
' 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()
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
// Sends the HttpWebRequest and waits for response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Displays all the headers present in the response received from the URI.
Console.WriteLine("\r\nThe following headers were received in the response:");
// Displays each header and it's key associated with the response.
for(int i=0; i < myHttpWebResponse.Headers.Count; ++i)
Console.WriteLine("\nHeader Name:{0}, Value :{1}",myHttpWebResponse.Headers.Keys[i],myHttpWebResponse.Headers[i]);
// Releases the resources of the response.
myHttpWebResponse.Close();
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest^ myHttpWebRequest = dynamic_cast<HttpWebRequest^>(WebRequest::Create( url ));
// Sends the HttpWebRequest and waits for response.
HttpWebResponse^ myHttpWebResponse = dynamic_cast<HttpWebResponse^>(myHttpWebRequest->GetResponse());
// Displays all the headers present in the response received from the URI.
Console::WriteLine( "\r\nThe following headers were received in the response:" );
// Displays each header and its key associated with the response.
for ( int i = 0; i < myHttpWebResponse->Headers->Count; ++i )
Console::WriteLine( "\nHeader Name: {0}, Value : {1}",
myHttpWebResponse->Headers->Keys[ i ],
myHttpWebResponse->Headers[ (System::Net::HttpRequestHeader)i ] );
// Releases the resources of the response.
myHttpWebResponse->Close();
// Creates an HttpWebRequest for the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)
WebRequest.Create(url);
// Sends the HttpWebRequest and waits for response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)
myHttpWebRequest.GetResponse();
// Displays all the headers present in the response
// received from the URI.
Console.WriteLine("\r\nThe following headers were received"
+ " in the response:");
// Displays each header and it's key associated with the response.
for (int i = 0; i < myHttpWebResponse.get_Headers().get_Count();
++i) {
Console.WriteLine("\nHeader Name:{0}, Value :{1}",
myHttpWebResponse.get_Headers().get_Keys().get_Item(i),
myHttpWebResponse.get_Headers().get_Item(i));
} // Releases the resources of the response.
myHttpWebResponse.Close();
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
HttpWebResponse-Klasse
HttpWebResponse-Member
System.Net-Namespace