我需要在C#控制台应用程序中通过HTTP下载一个大文件(2GB)。问题在于,在下载了约1.2GB后,应用程序会耗尽内存。
这是我正在使用的代码:
WebClient request = new WebClient();
request.Credentials = new NetworkCredential(username, password);
byte[] fileData = request.DownloadData(baseURL + fName);
正如您所看到的...我直接将文件读入内存。如果我从HTTP中以块的形式读回数据并将其写入磁盘上的文件,我相信我可以解决这个问题。
我该如何做到这一点?