Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

HttpWebResponse.ContentEncoding Property

Gets the method used to encode the body of the response.

[Visual Basic]
Public ReadOnly Property ContentEncoding As String
[C#]
public string ContentEncoding {get;}
[C++]
public: __property String* get_ContentEncoding();
[JScript]
public function get ContentEncoding() : String;

Property Value

A string describing the method used to encode the body of the response.

Exceptions

Exception Type Condition
ObjectDisposedException The current instance has been disposed.

Remarks

The ContentEncoding property contains the value of the Content-Encoding header returned with the response.

Example

[Visual Basic, C#, C++] The following example uses the ContentEncoding property to obtain the value of the Content-Encoding header returned with the response.

[Visual Basic] 
Try
   Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
   Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
   
   Console.WriteLine(("The encoding method used is: " + myHttpWebResponse.ContentEncoding))
   Console.WriteLine(("The character set used is :" + myHttpWebResponse.CharacterSet))
   
   Dim seperator As Char = "/"c
   Dim contenttype As [String] = myHttpWebResponse.ContentType
   ' Retrieve 'text' if the content type is of 'text/html.
   Dim maintype As [String] = contenttype.Substring(0, contenttype.IndexOf(seperator))
   ' Display only 'text' type.
   If [String].Compare(maintype, "text") = 0 Then
      Console.WriteLine(ControlChars.NewLine + " Content type is 'text'.")
      

[C#] 
try 
       {    
        HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url); 
        HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse(); 

        Console.WriteLine("The encoding method used is: " + myHttpWebResponse.ContentEncoding);
        Console.WriteLine("The character set used is :" + myHttpWebResponse.CharacterSet);

        char seperator = '/';
        String contenttype = myHttpWebResponse.ContentType;
        // Retrieve 'text' if the content type is of 'text/html.
        String maintype = contenttype.Substring(0,contenttype.IndexOf(seperator));
        // Display only 'text' type.
        if (String.Compare(maintype,"text") == 0) 
            {
            Console.WriteLine("\n Content type is 'text'.");


[C++] 
try {
   HttpWebRequest* myHttpWebRequest =
      dynamic_cast<HttpWebRequest*>(WebRequest::Create(url));
   HttpWebResponse* myHttpWebResponse =
      dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());

   Console::WriteLine(S"The encoding method used is: {0}",
      myHttpWebResponse->ContentEncoding);
   Console::WriteLine(S"The character set used is : {0}",
      myHttpWebResponse->CharacterSet);

   char separator = '/';
   String*  contenttype = myHttpWebResponse->ContentType;
   // Retrieve 'text' if the content type is of 'text/html.
   String*  maintype = contenttype->Substring(0, contenttype->IndexOf(separator));
   // Display only 'text' type.
   if (String::Compare(maintype, S"text") == 0) {
      Console::WriteLine(S"\n Content type is 'text'.");

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

HttpWebResponse Class | HttpWebResponse Members | System.Net Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.