Поделиться через


HttpWebRequest.AllowReadStreamBuffering Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When overridden in a descendant class, gets or sets a value that indicates whether to buffer the data read from the Internet resource.

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

Syntax

'Declaration
Public Overridable Property AllowReadStreamBuffering As Boolean
public virtual bool AllowReadStreamBuffering { get; set; }

Property Value

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

Exceptions

Exception Condition
NotImplementedException

This property is not implemented.

Remarks

When AllowReadStreamBuffering is true, the data is buffered in memory so it is ready to be read by the application.

The AllowReadStreamBuffering property is supported by both the browser and the client HTTP stack.

The AllowReadStreamBuffering property affects when the callback from BeginGetResponse method is called. When the AllowReadStreamBuffering property is true, the callback is raised once the entire stream has been downloaded into memory. When the AllowReadStreamBuffering property is false, the callback is raised as soon as the stream is available for reading which may be before all data has arrived.

If the application creates a class which derives from HttpWebRequest and does not override the AllowReadStreamBuffering property and then tries to get or set the AllowReadStreamBuffering property, a NotImplementedException is thrown.

If an application implements a custom WebRequest class and does not override the AllowReadStreamBuffering property, then the NotImplementedException is thrown.

Examples

    ' Change this Uri to a public server
    Dim myUri As System.Uri = New Uri("https://www.contoso.com")

    ' Create a 'HttpWebRequest' object.
    Dim myHttpWebRequest As HttpWebRequest = WebRequest.Create(myUri)

    ' Get the 'AllowReadStreamBuffering' property and print the current value
    outputBlock.Text &= "AllowReadStreamBuffering is "
    If myHttpWebRequest.AllowReadStreamBuffering Then
      outputBlock.Text &= "true"
      outputBlock.Text &= vbCrLf
    Else    
      outputBlock.Text &= "false"
      outputBlock.Text &= vbCrLf
    End If

    ' Set the 'AllowReadStreamBuffering' property to true.
    myHttpWebRequest.AllowReadStreamBuffering= False

    ' Now call HttpWebRequest.BeginGetResponse() 

        // Change this Uri to a public server
        System.Uri myUri = new Uri("https://www.contoso.com");

        // Create a 'HttpWebRequest' object.
        HttpWebRequest myHttpWebRequest=(HttpWebRequest)WebRequest.Create(myUri);

        // Get the 'AllowReadStreamBuffering' property and print the current value
        outputBlock.Text += "AllowReadStreamBuffering is ";
        if (myHttpWebRequest.AllowReadStreamBuffering)
            outputBlock.Text += "true\n";
        else    
            outputBlock.Text += "false\n";

        // Set the 'AllowReadStreamBuffering' property to true.
        myHttpWebRequest.AllowReadStreamBuffering= false;

        // Now call HttpWebRequest.BeginGetResponse() 

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.