WebResponse.ContentType プロパティ
派生クラスでオーバーライドされると、受信しているデータのコンテンツ タイプを取得または設定します。
名前空間: System.Net
アセンブリ: System (system.dll 内)
構文
Public Overridable Property ContentType As String
Dim instance As WebResponse Dim value As String value = instance.ContentType instance.ContentType = value


ContentType プロパティは、インターネット リソースからの応答の MIME コンテンツ タイプが確認された場合に、その値を格納します。
![]() |
---|
WebResponse クラスは、abstract クラスです。実行時の WebResponse インスタンスの実際の動作は、WebRequest.GetResponse で返される派生クラスによって決まります。既定値および例外の詳細については、HttpWebResponse や FileWebResponse などの派生クラスの説明を参照してください。 |

ContentType プロパティを使用して、応答のコンテンツ タイプを取得する例を次に示します。
' 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()
// 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. 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}", System.Convert.ToString(myWebResponse.get_ContentLength()), System.Convert.ToString(myWebResponse.get_ContentType())); // Release resources of response object. myWebResponse.Close();

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からWebResponse.ContentType プロパティを検索する場合は、下記のリンクをクリックしてください。

- WebResponse.ContentType プロパティのページへのリンク