Export (0) Print
Expand All

HttpWebRequest.AllowWriteStreamBuffering Property

Gets or sets a value that indicates whether to buffer the data sent to the Internet resource.

[Visual Basic]
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);

Property Value

true to enable buffering of the data sent to the Internet resource; false to disable buffering. The default is true.

Remarks

When AllowWriteStreamBuffering is true, the data is buffered in memory so it is ready to be resent in the event of redirections or authentication requests.

Notes to Implementers:  Setting AllowWriteStreamBuffering true might cause performance problems when uploading large datasets because the data buffer could use all available memory.

.NET Compact Framework Platform Note:  For performance considerations, the default value for AllowWriteStreamBuffering is false; however, it is important to note that if verbs require entity data (such as POST), redirection and authentication might not occur. To implement the full .NET Framework behavior for HTTP requests, set AllowWriteStreamBuffering to true.

Example

[Visual Basic, C#, C++] The following example uses the AllowWriteStreamBuffering property to disable data buffering.

[Visual Basic] 
' A new 'HttpWebRequest' object is created                 
Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create("http://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 (http://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("http://www.contoso.com/codesnippets/next.asp");
            // Set AllowWriteStreamBuffering to 'false'. 
            myHttpWebRequest.AllowWriteStreamBuffering=false;
            Console.WriteLine("\nPlease Enter the data to be posted to the (http://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"http://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 (http://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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

HttpWebRequest Class | HttpWebRequest Members | System.Net Namespace

Show:
© 2014 Microsoft