Freigeben über


HttpWebRequest.AllowWriteStreamBuffering-Eigenschaft

Ruft einen Wert ab, der angibt, ob die an die Internetressource gesendeten Daten gepuffert werden sollen, oder legt diesen fest.

Namespace: System.Net
Assembly: System (in system.dll)

Syntax

'Declaration
Public Property AllowWriteStreamBuffering As Boolean
'Usage
Dim instance As HttpWebRequest
Dim value As Boolean

value = instance.AllowWriteStreamBuffering

instance.AllowWriteStreamBuffering = value
public bool AllowWriteStreamBuffering { get; set; }
public:
property bool AllowWriteStreamBuffering {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_AllowWriteStreamBuffering ()

/** @property */
public void set_AllowWriteStreamBuffering (boolean value)
public function get AllowWriteStreamBuffering () : boolean

public function set AllowWriteStreamBuffering (value : boolean)

Eigenschaftenwert

true aktiviert das Puffern der an die Internetressource gesendeten Daten, false deaktiviert das Puffern. Der Standardwert ist true.

Hinweise

Wenn AllowWriteStreamBuffering auf true festgelegt ist, werden die Daten im Speicher gepuffert, sodass sie bei Umleitungen oder Authentifizierungsanforderungen erneut gesendet werden können.

Hinweise für Implementierer Durch das Festlegen von AllowWriteStreamBuffering auf true können beim Uploaden von großen Datasets Leistungsprobleme auftreten, da der Datenpuffer u. U. den gesamten verfügbaren Arbeitsspeicher in Anspruch nimmt.

Hinweis zu Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows CE: Im Hinblick auf die Leistungsoptimierung ist der Standardwert für diese Eigenschaft false. Beachten Sie jedoch, dass möglicherweise keine Umleitung bzw. Authentifizierung stattfindet, wenn für Verben Entitätsdaten, z. B. POST, erforderlich sind. Wenn Sie die vollständige .NET Framework-Funktionalität für HTTP-Anforderungen implementieren möchten, legen Sie AllowWriteStreamBuffering auf true fest.

Beispiel

Im folgenden Codebeispiel wird die AllowWriteStreamBuffering-Eigenschaft verwendet, um das Puffern von Daten zu deaktivieren.

 ' 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)
// 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();
// 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 = 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("https://www.contoso.com/codesnippets/"
    + "next.asp"));
// Set AllowWriteStreamBuffering to 'false'. 
myHttpWebRequest.set_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.set_Method("POST");
ASCIIEncoding encodedData =  new ASCIIEncoding();
ubyte byteArray[] = encodedData.GetBytes(postData);
// Set 'ContentType' property of the 'HttpWebRequest' class to 
// "application/x-www-form-urlencoded".
myHttpWebRequest.set_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.set_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());

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

HttpWebRequest-Klasse
HttpWebRequest-Member
System.Net-Namespace