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

Public Overrides Property ContentType As String
Dim instance As HttpWebRequest Dim value As String value = instance.ContentType instance.ContentType = value
public: virtual property String^ ContentType { String^ get () override; void set (String^ value) override; }
/** @property */ public String get_ContentType () /** @property */ public void set_ContentType (String value)
public override function get ContentType () : String public override function set ContentType (value : String)
Content-type HTTP ヘッダーの値。既定値は null 参照 (Visual Basic では Nothing) です。

ContentType プロパティは、要求のメディア タイプを格納します。ContentType プロパティに割り当てた値は、要求が Content-type HTTP ヘッダーを送信するときに、既存のすべての内容と置き換えられます。
Content-type HTTP ヘッダーをクリアするには、ContentType プロパティを null 参照 (Visual Basic では Nothing) に設定します。
![]() |
---|
このプロパティの値は WebHeaderCollection に格納されます。WebHeaderCollection が設定されている場合、プロパティ値は失われます。 |

ContentType プロパティを設定するコード例を次に示します。
' Set the 'Method' property of the 'Webrequest' to 'POST'. myHttpWebRequest.Method = "POST" Console.WriteLine(ControlChars.Cr + "Please enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :") ' Create a new string object to POST data to the Url. Dim inputData As String = Console.ReadLine() Dim postData As String = "firstone" + ChrW(61) + inputData Dim encoding As New ASCIIEncoding() Dim byte1 As Byte() = encoding.GetBytes(postData) ' Set the content type of the data being posted. myHttpWebRequest.ContentType = "application/x-www-form-urlencoded" ' Set the content length of the string being posted. myHttpWebRequest.ContentLength = byte1.Length Dim newStream As Stream = myHttpWebRequest.GetRequestStream() newStream.Write(byte1, 0, byte1.Length) Console.WriteLine("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength) newStream.Close()
// Set the 'Method' property of the 'Webrequest' to 'POST'. myHttpWebRequest.Method = "POST"; Console.WriteLine ("\nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :"); // Create a new string object to POST data to the Url. string inputData = Console.ReadLine (); string postData = "firstone=" + inputData; ASCIIEncoding encoding = new ASCIIEncoding (); byte[] byte1 = encoding.GetBytes (postData); // Set the content type of the data being posted. myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"; // Set the content length of the string being posted. myHttpWebRequest.ContentLength = byte1.Length; Stream newStream = myHttpWebRequest.GetRequestStream (); newStream.Write (byte1, 0, byte1.Length); Console.WriteLine ("The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest.ContentLength); // Close the Stream object. newStream.Close ();
// Set the 'Method' property of the 'Webrequest' to 'POST'. myHttpWebRequest->Method = "POST"; Console::WriteLine( "\nPlease enter the data to be posted to the (http://www.contoso.com/codesnippets/next.asp) Uri :" ); // Create a new String* Object* to POST data to the Url. String^ inputData = Console::ReadLine(); String^ postData = String::Concat( "firstone= ", inputData ); ASCIIEncoding^ encoding = gcnew ASCIIEncoding; array<Byte>^ byte1 = encoding->GetBytes( postData ); // Set the content type of the data being posted. myHttpWebRequest->ContentType = "application/x-www-form-urlencoded"; // Set the content length of the String* being posted. myHttpWebRequest->ContentLength = byte1->Length; Stream^ newStream = myHttpWebRequest->GetRequestStream(); newStream->Write( byte1, 0, byte1->Length ); Console::WriteLine( "The value of 'ContentLength' property after sending the data is {0}", myHttpWebRequest->ContentLength ); // Close the Stream Object*. newStream->Close();
// Set the 'Method' property of the 'Webrequest' to 'POST'. myHttpWebRequest.set_Method("POST"); Console.WriteLine("\nPlease enter the data to be posted to the " + "(http://www.contoso.com/codesnippets/next.asp) Uri :"); // Create a new string object to POST data to the Url. String inputData = Console.ReadLine(); String postData = "firstone=" + inputData; ASCIIEncoding encoding = new ASCIIEncoding(); ubyte byte1[] = encoding.GetBytes(postData); // Set the content type of the data being posted. myHttpWebRequest.set_ContentType("application/x-www-form-" +"urlencoded"); // Set the content length of the string being posted. myHttpWebRequest.set_ContentLength(postData.length()); Stream newStream = myHttpWebRequest.GetRequestStream(); newStream.Write(byte1, 0, byte1.length); Console.WriteLine("The value of 'ContentLength' property after" + " sending the data is {0}", System.Convert.ToString(myHttpWebRequest.get_ContentLength())); // Close the Stream object. newStream.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に収録されているすべての辞書からHttpWebRequest.ContentType プロパティを検索する場合は、下記のリンクをクリックしてください。

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