Tag: 流出

使用HttpWebRequest流式传输大型文件时出现内存exception

当使用大文件的Http.Put时,我得到Out of Memory Exception。 我正在使用代码中显示的异步模型。 我正在尝试将8K数据块发送到Windows 2008 R2服务器。 当我尝试写入超过536,868,864字节的数据块时,会始终出现exception。 下面的代码片段中的requestStream.Write方法发生exception。 寻找原因? 注意:较小的文件是PUT OK。 如果我写入本地FileStream,逻辑也可以工作。 在Win 7 Ultimate客户端计算机上运行VS 2010,.Net 4.0。 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“Http://website/FileServer/filename”); request.Method = WebRequestMethods.Http.Put; request.SendChunked = true; request.AllowWriteStreamBuffering = true; … request.BeginGetRequestStream( new AsyncCallback(EndGetStreamCallback), state); … int chunk = 8192; // other values give same result …. private static void EndGetStreamCallback(IAsyncResult ar) { […]