WebResponse.ContentType Propiedad

Definición

Cuando se realizan omisiones en una clase derivada, obtiene o establece el tipo de contenido de los datos recibidos.

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

Valor de propiedad

Cadena que contiene el tipo de contenido de la respuesta.

Excepciones

Se intenta por todos los medios obtener o establecer la propiedad, cuando la propiedad no se reemplaza en una clase descendiente.

Ejemplos

En el ejemplo siguiente se usa la ContentType propiedad para obtener el tipo de contenido de la respuesta.

// 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()

Comentarios

La ContentType propiedad contiene el tipo de contenido MIME de la respuesta del recurso de Internet, si se conoce.

Nota

La WebResponse clase es una abstract clase . El comportamiento real de las instancias en tiempo de WebResponse ejecución viene determinado por la clase descendiente devuelta por WebRequest.GetResponse. Para obtener más información sobre los valores y excepciones predeterminados, consulte la documentación de las clases descendientes, como HttpWebResponse y FileWebResponse.

Se aplica a

Consulte también