次の方法で共有


HttpWebRequest.AllowWriteStreamBuffering プロパティ

インターネット リソースに送信するデータをバッファリングするかどうかを示す値を取得または設定します。

Public Property AllowWriteStreamBuffering As Boolean
[C#]
public bool AllowWriteStreamBuffering {get; set;}
[C++]
public: __property bool get_AllowWriteStreamBuffering();public: __property void set_AllowWriteStreamBuffering(bool);
[JScript]
public function get AllowWriteStreamBuffering() : Boolean;public function set AllowWriteStreamBuffering(Boolean);

プロパティ値

インターネット リソースに送信するデータのバッファリングを有効にする場合は true 。バッファリングを無効にする場合は false 。既定値は true です。

解説

AllowWriteStreamBufferingtrue の場合、データはメモリにバッファリングされるため、リダイレクト要求または認証要求が発生したときにすぐに再送信できます。

実装時の注意: AllowWriteStreamBufferingtrue に設定すると、大きなデータセットをアップロードするときに、パフォーマンス上の問題が生じることがあります。これは、データ バッファが、利用できるメモリをすべて使用してしまう可能性があるためです。

.NET Compact Framework - Windows CE .NET プラットフォームに関する注意点: パフォーマンス上の理由から、既定では、 AllowWriteStreamBufferingfalse に設定されています。ただし、動詞に POST などのエンティティ データが必要な場合は、リダイレクトと認証が行われない場合があることに注意してください。HTTP 要求に対する .NET Framework の機能を完全に実装するには、 AllowWriteStreamBufferingtrue に設定します。

使用例

[Visual Basic, C#, C++] AllowWriteStreamBuffering プロパティを使用して、データ バッファリングを無効にする例を次に示します。

 
' A new 'HttpWebRequest' object is created                 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("https://www.contoso.com/codesnippets/next.asp"), HttpWebRequest)
           ' AllowWriteStreamBuffering is set to 'false' 
myHttpWebRequest.AllowWriteStreamBuffering = False
Console.WriteLine(ControlChars.Cr + "Please Enter the data to be posted to the (https://www.contoso.com/codesnippets/next.asp) uri:")
Dim inputData As String = Console.ReadLine()
Dim postData As String = "firstone" + ChrW(61) + inputData
' 'Method' property of 'HttpWebRequest' class is set to POST.
myHttpWebRequest.Method = "POST"
Dim encodedData As New ASCIIEncoding()
Dim byteArray As Byte() = encodedData.GetBytes(postData)
' 'ContentType' property of the 'HttpWebRequest' class is set to "application/x-www-form-urlencoded".
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded"
' If the AllowWriteStreamBuffering property of HttpWebRequest is set to false,then contentlength has to be set to length of data to be posted else Exception(411) Length required is raised.
 myHttpWebRequest.ContentLength=byteArray.Length
Dim newStream As Stream = myHttpWebRequest.GetRequestStream()
newStream.Write(byteArray, 0, byteArray.Length)
newStream.Close()
Console.WriteLine(ControlChars.Cr + "Data has been posted to the Uri" + ControlChars.Cr + ControlChars.Cr + "Please wait for the response..........")
' The response object of 'HttpWebRequest' is assigned to a 'HttpWebResponse' variable.
Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)

[C#] 

            // Create a new 'HttpWebRequest' object to the mentioned Uri.                
            HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create("https://www.contoso.com/codesnippets/next.asp");
            // Set AllowWriteStreamBuffering to 'false'. 
            myHttpWebRequest.AllowWriteStreamBuffering=false;
            Console.WriteLine("\nPlease Enter the data to be posted to the (https://www.contoso.com/codesnippets/next.asp) uri:");
            string inputData =Console.ReadLine();
            string postData="firstone="+inputData;
            // Set 'Method' property of 'HttpWebRequest' class to POST.
            myHttpWebRequest.Method="POST";
            ASCIIEncoding encodedData=new ASCIIEncoding();
            byte[]  byteArray=encodedData.GetBytes(postData);
            // Set 'ContentType' property of the 'HttpWebRequest' class to "application/x-www-form-urlencoded".
            myHttpWebRequest.ContentType="application/x-www-form-urlencoded";
            // If the AllowWriteStreamBuffering property of HttpWebRequest is set to false,the contentlength has to be set to length of data to be posted else Exception(411) is raised.
            myHttpWebRequest.ContentLength=byteArray.Length;
            Stream newStream=myHttpWebRequest.GetRequestStream();
            newStream.Write(byteArray,0,byteArray.Length);
            newStream.Close();
            Console.WriteLine("\nData has been posted to the Uri\n\nPlease wait for the response..........");
            // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
            HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();

[C++] 

      // Create a new 'HttpWebRequest' object to the mentioned Uri.
      HttpWebRequest* myHttpWebRequest =
         dynamic_cast<HttpWebRequest*>(WebRequest::Create(S"https://www.contoso.com/codesnippets/next.asp"));
      // Set AllowWriteStreamBuffering to 'false'.
      myHttpWebRequest->AllowWriteStreamBuffering=false;
      Console::WriteLine(S"\nPlease Enter the data to be posted to the (https://www.contoso.com/codesnippets/next.asp) uri:");
      String* inputData =Console::ReadLine();
      String* postData = String::Concat(S"firstone= ", inputData);
      // Set 'Method' property of 'HttpWebRequest' class to POST.
      myHttpWebRequest->Method=S"POST";
      ASCIIEncoding* encodedData = new ASCIIEncoding();
      Byte byteArray[]=encodedData->GetBytes(postData);
      // Set 'ContentType' property of the 'HttpWebRequest' class to S"application/x-www-form-urlencoded".
      myHttpWebRequest->ContentType = S"application/x-www-form-urlencoded";
      // If the AllowWriteStreamBuffering property of HttpWebRequest is set to false, the contentlength has to be set to length of data to be posted else Exception(411) is raised.
      myHttpWebRequest->ContentLength=byteArray->Length;
      Stream* newStream=myHttpWebRequest->GetRequestStream();
      newStream->Write(byteArray, 0, byteArray->Length);
      newStream->Close();
      Console::WriteLine(S"\nData has been posted to the Uri\n\nPlease wait for the response..........");
      // Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
      HttpWebResponse* myHttpWebResponse =
         dynamic_cast<HttpWebResponse*>(myHttpWebRequest->GetResponse());

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

HttpWebRequest クラス | HttpWebRequest メンバ | System.Net 名前空間