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

HttpWebResponse.CharacterSet Property

Gets the character set of the response.

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

Property Value

A string containing the character set of the response.

Exceptions

Exception Type Condition
ObjectDisposedException The current instance has been disposed.

Remarks

The CharacterSet property contains a value describing the character set of the response. This character set information is taken from the header returned with the response.

Example

[Visual Basic, C#, C++] The following example obtains the character set of 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

Show:
© 2014 Microsoft. All rights reserved.