次の方法で共有


HttpWebResponse.ContentEncoding プロパティ

応答の本文をエンコードするために使用するメソッドを取得します。

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

プロパティ値

応答の本文をエンコードするために使用するメソッドを記述する文字列。

例外

例外の種類 条件
ObjectDisposedException 現在のインスタンスは破棄されています。

解説

ContentEncoding プロパティは、応答で返される Content-Encoding ヘッダーの値を格納します。

使用例

[Visual Basic, C#, C++] ContentEncoding プロパティを使用して、応答で返される Content-Encoding ヘッダーの値を取得する例を次に示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

HttpWebResponse クラス | HttpWebResponse メンバ | System.Net 名前空間