Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

HttpWebRequest.AllowWriteStreamBuffering Property

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

Namespace:  System.Net
Assembly:  System (in System.dll)
public bool AllowWriteStreamBuffering { get; set; }

Property Value

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

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 to true might cause performance problems when uploading large datasets because the data buffer could use all available memory.

The following code example uses the AllowWriteStreamBuffering property to disable data buffering.



			// 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();


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.