HttpWebRequest.AllowWriteStreamBuffering Özellik

Tanım

İnternet kaynağına gönderilen verilerin arabelleğe alınıp alınmayacağını belirten bir değer alır veya ayarlar.

C#
public virtual bool AllowWriteStreamBuffering { get; set; }
C#
public bool AllowWriteStreamBuffering { get; set; }

Özellik Değeri

İnternet kaynağına gönderilen verilerin arabelleğe alınabilmesini true; Arabelleği devre dışı bırakmak için false. Varsayılan değer true.

Örnekler

Aşağıdaki kod örneği, veri arabelleğe almayı devre dışı bırakmak için AllowWriteStreamBuffering özelliğini kullanır.

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

Açıklamalar

Dikkat

WebRequest, HttpWebRequest, ServicePointve WebClient kullanım dışıdır ve bunları yeni geliştirme için kullanmamalısınız. Bunun yerine HttpClient kullanın.

AllowWriteStreamBuffering trueolduğunda veriler bellekte arabelleğe alınıp yeniden yönlendirmeler veya kimlik doğrulama istekleri durumunda yeniden yüklenmeye hazır olur.

Devralanlara Notlar

Veri arabelleği tüm kullanılabilir belleği kullanabileceğinden, AllowWriteStreamBufferingtrue olarak ayarlanması büyük veri kümelerini karşıya yüklerken performans sorunlarına neden olabilir.

Şunlara uygulanır

Ürün Sürümler
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1