此页面有用吗?
您对此内容的反馈非常重要。 请告诉我们您的想法。
更多反馈?
1500 个剩余字符
导出 (0) 打印
全部展开

HttpWebRequest.AllowWriteStreamBuffering 属性

获取或设置一个值,该值指示是否对发送到 Internet 资源的数据进行缓冲处理。

命名空间:System.Net
程序集:System(在 system.dll 中)

public bool AllowWriteStreamBuffering { get; set; }
/** @property */
public boolean get_AllowWriteStreamBuffering ()

/** @property */
public void set_AllowWriteStreamBuffering (boolean value)

public function get AllowWriteStreamBuffering () : boolean

public function set AllowWriteStreamBuffering (value : boolean)

属性值

true 允许对发送到 Internet 资源的数据进行缓冲处理,false 禁用缓冲处理。默认为 true

AllowWriteStreamBufferingtrue 时,数据缓存在内存中,以便随时可以在重定向或身份验证请求时重新发送。

给实现者的说明AllowWriteStreamBuffering 设置为 true 可能会在上载大型数据集时造成性能问题,原因是数据缓冲区可能占用了所有的可用内存。

Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows CE 平台说明: 出于性能考虑,此属性的默认值为 false;但是请注意,如果谓词需要实体数据(如 POST),就可能不会进行重定向及身份验证。要为 HTTP 请求实现完整的 .NET Framework 行为,请将 AllowWriteStreamBuffering 设置为 true

下面的代码示例使用 AllowWriteStreamBuffering 属性来禁用数据缓冲。


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

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

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

社区附加资源

添加
显示:
© 2015 Microsoft