HttpListenerRequest.ContentType プロパティ
アセンブリ: System (system.dll 内)

public string ContentType { get; }
要求の Content-Type ヘッダーのテキストを格納している String。

クライアントが要求に本体データを含めた場合、Content-Type ヘッダーで本体データの MIME (Multipurpose Internet Mail Extensions) タイプが宣言されています。たとえば、POST メソッドを使用した場合に Web フォームから返されるデータの既定の MIME タイプは、application/x-www-form-urlencoded です。
要求のヘッダーの完全な一覧については、HttpRequestHeader 列挙体と、RFC 2616 (http://www.rfc-editor.org) を参照してください。

public static void ShowRequestData (HttpListenerRequest request) { if (!request.HasEntityBody) { Console.WriteLine("No client data was sent with the request."); return; } System.IO.Stream body = request.InputStream; System.Text.Encoding encoding = request.ContentEncoding; System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding); if (request.ContentType != null) { Console.WriteLine("Client data content type {0}", request.ContentType); } Console.WriteLine("Client data content length {0}", request.ContentLength64); Console.WriteLine("Start of client data:"); // Convert the data to a string and display it on the console. string s = reader.ReadToEnd(); Console.WriteLine(s); Console.WriteLine("End of client data:"); body.Close(); reader.Close(); // If you are finished with the request, it should be closed also. }

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


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