Freigeben über


HttpWebRequest.AllowWriteStreamBuffering Eigenschaft

Definition

Dient zum Abrufen oder Festlegen eines Werts, der angibt, ob die an die Internetressource gesendeten Daten gepuffert werden sollen.

public:
 virtual property bool AllowWriteStreamBuffering { bool get(); void set(bool value); };
public:
 property bool AllowWriteStreamBuffering { bool get(); void set(bool value); };
public virtual bool AllowWriteStreamBuffering { get; set; }
public bool AllowWriteStreamBuffering { get; set; }
member this.AllowWriteStreamBuffering : bool with get, set
Public Overridable Property AllowWriteStreamBuffering As Boolean
Public Property AllowWriteStreamBuffering As Boolean

Eigenschaftswert

true die Pufferung der an die Internetressource gesendeten Daten zu ermöglichen; false, um die Pufferung zu deaktivieren. Der Standardwert ist true.

Beispiele

Im folgenden Codebeispiel wird die AllowWriteStreamBuffering-Eigenschaft verwendet, um die Datenpufferung zu deaktivieren.

// 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 = String::Concat( "firstone= ", inputData );
// Set 'Method' property of 'HttpWebRequest' class to POST.
myHttpWebRequest->Method = "POST";
ASCIIEncoding^ encodedData = gcnew ASCIIEncoding;
array<Byte>^ byteArray = encodedData->GetBytes( postData );
// Set 'ContentType' property of the 'HttpWebRequest' class to S"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() );

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

Hinweise

Vorsicht

WebRequest, HttpWebRequest, ServicePointund WebClient sind veraltet, und Sie sollten sie nicht für die neue Entwicklung verwenden. Verwenden Sie stattdessen HttpClient.

Wenn AllowWriteStreamBufferingtrueist, werden die Daten im Arbeitsspeicher gepuffert, sodass sie bei Umleitungen oder Authentifizierungsanforderungen erneut eingelöst werden kann.

Hinweise für Vererber

Das Festlegen AllowWriteStreamBuffering auf true kann beim Hochladen großer Datasets zu Leistungsproblemen führen, da der Datenpuffer den gesamten verfügbaren Arbeitsspeicher verwenden kann.

Gilt für: