HttpWebRequest.GetRequestStream メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpWebRequest.GetRequestStream メソッドの意味・解説 

HttpWebRequest.GetRequestStream メソッド

要求データ書き込むために使用する Stream オブジェクト取得します

名前空間: System.Net
アセンブリ: System (system.dll 内)
構文構文

Public Overrides Function
 GetRequestStream As Stream
Dim instance As HttpWebRequest
Dim returnValue As Stream

returnValue = instance.GetRequestStream
public override Stream GetRequestStream ()
public:
virtual Stream^ GetRequestStream () override
public Stream GetRequestStream ()

戻り値
要求データ書き込むために使用する Stream

例外例外
例外種類条件

ProtocolViolationException

Method プロパティGET または HEAD です。

または

KeepAlivetrue で、AllowWriteStreamBuffering は false で、ContentLength は -1 で、SendChunked は false で、MethodPOST または PUT です。

InvalidOperationException

GetRequestStream メソッドが、何度も呼び出されています。

または

TransferEncoding に値が設定されSendChunkedfalse です。

NotSupportedException

要求キャッシュ検証コントロールで、この要求応答キャッシュから取得できることが示されましたが、データ書き込みを行う要求キャッシュ使用できません。この例外は、キャッシュ検証コントロール不適切カスタム実装使用した場合発生することがあります

WebException

Abort は既に呼び出されました。

または

要求タイムアウト時間経過しました

または

要求の処理中にエラー発生しました

ObjectDisposedException

.NET Compact Framework アプリケーションで、コンテンツ長が 0 の要求ストリーム取得されず、適切に閉じられました。コンテンツ長が 0 の要求の処理の詳細については、「.NET Compact Frameworkネットワーク プログラミング」を参照してください

解説解説
使用例使用例

GetRequestStream メソッド使用してストリーム インスタンス返すコード例次に示します

' 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();
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からHttpWebRequest.GetRequestStream メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHttpWebRequest.GetRequestStream メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHttpWebRequest.GetRequestStream メソッドを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HttpWebRequest.GetRequestStream メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpWebRequest.GetRequestStream メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS