WebResponse.ContentType Propriedade

Definição

Quando substituído em uma classe derivada, obtém ou define o tipo de conteúdo dos dados que estão sendo recebidos.

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 da propriedade

Uma cadeia de caracteres que contém o tipo de conteúdo da resposta.

Exceções

Tentativa de obter ou definir a propriedade, quando a propriedade não foi substituída em uma classe descendente.

Exemplos

O exemplo a seguir usa a ContentType propriedade para obter o tipo de conteúdo da resposta.

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

Comentários

A ContentType propriedade contém o tipo de conteúdo MIME da resposta do recurso da Internet, se conhecido.

Observação

A WebResponse classe é uma abstract classe . O comportamento real das instâncias em tempo de WebResponse execução é determinado pela classe descendente retornada por WebRequest.GetResponse. Para obter mais informações sobre valores padrão e exceções, consulte a documentação das classes descendentes, como HttpWebResponse e FileWebResponse.

Aplica-se a

Confira também