WebRequest.GetRequestStream メソッド

定義

派生クラスでオーバーライドされると、インターネット リソースにデータを書き込むための Stream を返します。

public:
 virtual System::IO::Stream ^ GetRequestStream();
public virtual System.IO.Stream GetRequestStream ();
abstract member GetRequestStream : unit -> System.IO.Stream
override this.GetRequestStream : unit -> System.IO.Stream
Public Overridable Function GetRequestStream () As Stream

戻り値

インターネット リソースにデータを書き込む Stream

例外

メソッドが派生クラスでオーバーライドされていないのに、そのメソッドへのアクセスが試行されました。

次の例では、 メソッドを GetRequestStream 使用してストリームを取得し、そのストリームのデータを書き込みます。

// Set the 'ContentType' property of the WebRequest.
myWebRequest->ContentType = "application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest->ContentLength = byteArray->Length;
Stream^ newStream = myWebRequest->GetRequestStream();
newStream->Write( byteArray, 0, byteArray->Length );

// Close the Stream object.
newStream->Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse^ myWebResponse = myWebRequest->GetResponse();

// Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType="application/x-www-form-urlencoded";

// Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength=byteArray.Length;
Stream newStream=myWebRequest.GetRequestStream();
newStream.Write(byteArray,0,byteArray.Length);

// Close the Stream object.
newStream.Close();

// Assign the response object of 'WebRequest' to a 'WebResponse' variable.
WebResponse myWebResponse=myWebRequest.GetResponse();


' Set the 'ContentType' property of the WebRequest.
myWebRequest.ContentType = "application/x-www-form-urlencoded"

' Set the 'ContentLength' property of the WebRequest.
myWebRequest.ContentLength = byteArray.Length
Dim newStream As Stream = myWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)

' Close the Stream object.
newStream.Close()

' Assign the response object of 'WebRequest' to a 'WebResponse' variable.
Dim myWebResponse As WebResponse = myWebRequest.GetResponse()

注釈

メソッドは GetRequestStream 、インターネット リソースにデータを送信する要求を開始し、インターネット リソースにデータを Stream 送信するためのインスタンスを返します。

メソッドは GetRequestStream 、 への同期アクセスを提供します Stream。 非同期アクセスの場合は、 メソッドと EndGetRequestStream メソッドをBeginGetRequestStream使用します。

注意

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

適用対象

こちらもご覧ください