英語で読む

次の方法で共有


WebResponse.ContentType プロパティ

定義

派生クラスでオーバーライドされると、受信しているデータのコンテンツ タイプを取得または設定します。

C#
public abstract string ContentType { get; }
C#
public virtual string ContentType { get; set; }

プロパティ値

応答のコンテンツ タイプを格納する文字列。

例外

プロパティが派生クラスでオーバーライドされていないのに、そのプロパティの取得または設定が試行されました。

次の例では、 プロパティを ContentType 使用して応答のコンテンツ タイプを取得します。

C#

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

注釈

プロパティには ContentType 、インターネット リソースからの応答の MIME コンテンツ タイプ (既知の場合) が含まれます。

注意

クラスは WebResponse クラスです abstract 。 実行時のインスタンスの実際の WebResponse 動作は、 によって返される子孫クラスによって WebRequest.GetResponse決まります。 既定値と例外の詳細については、 や FileWebResponseなどのHttpWebResponse子孫クラスのドキュメントを参照してください。

適用対象

製品 バージョン
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

こちらもご覧ください