WebResponse.ContentType Eigenschaft

Definition

Ruft beim Überschreiben in einer abgeleiteten Klasse den Inhaltstyp der empfangenen Daten ab oder legt diesen fest.

public:
 abstract property System::String ^ ContentType { System::String ^ get(); };
public:
 virtual property System::String ^ ContentType { System::String ^ get(); void set(System::String ^ value); };
public abstract string ContentType { get; }
public virtual string ContentType { get; set; }
member this.ContentType : string
member this.ContentType : string with get, set
Public MustOverride ReadOnly Property ContentType As String
Public Overridable Property ContentType As String

Eigenschaftswert

Eine Zeichenfolge, die den Inhaltstyp der Antwort enthält.

Ausnahmen

Es wurde versucht, die Eigenschaft abzurufen oder festzulegen, obwohl die Eigenschaft in einer Nachfolgerklasse nicht überschrieben wurde.

Beispiele

Im folgenden Beispiel wird die ContentType -Eigenschaft verwendet, um den Inhaltstyp der Antwort abzurufen.

// Create a 'WebRequest' with the specified url.
WebRequest^ myWebRequest = WebRequest::Create( "http://www.contoso.com" );

// Send the 'WebRequest' and wait for response.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Display the content length and content type received as headers in the response object.
Console::WriteLine( "\nContent length : {0}, Content Type : {1}", myWebResponse->ContentLength, myWebResponse->ContentType );

// Release resources of response object.
myWebResponse->Close();

         // Create a 'WebRequest' with the specified url.
WebRequest myWebRequest = WebRequest.Create("http://www.contoso.com"); 

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse(); 

// Display the content length and content type received as headers in the response object.
Console.WriteLine("\nContent length :{0}, Content Type : {1}", 
                             myWebResponse.ContentLength, 
                             myWebResponse.ContentType);  

// Release resources of response object.
myWebResponse.Close();

' Create a 'WebRequest' with the specified url. 	
Dim myWebRequest As WebRequest = WebRequest.Create("www.contoso.com")

' Send the 'WebRequest' and wait for response.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

' The ContentLength and ContentType received as headers in the response object are also exposed as properties.
   ' These provide information about the length and type of the entity body in the response.
Console.WriteLine(ControlChars.Cr + "Content length :{0}, Content Type : {1}", myWebResponse.ContentLength, myWebResponse.ContentType)
myWebResponse.Close()

Hinweise

Die ContentType -Eigenschaft enthält den MIME-Inhaltstyp der Antwort aus der Internetressource, sofern bekannt.

Hinweis

Die WebResponse -Klasse ist eine abstract Klasse. Das tatsächliche Verhalten von WebResponse Instanzen zur Laufzeit wird durch die von WebRequest.GetResponsezurückgegebene Nachfolgerklasse bestimmt. Weitere Informationen zu Standardwerten und Ausnahmen finden Sie in der Dokumentation für die Nachfolgerklassen, z HttpWebResponse . B. und FileWebResponse.

Gilt für:

Weitere Informationen