目标: - 服务器端:验证凭据后将文件写入响应流。换句话说,没有对该文件的公共(public)访问权限。 - 客户端:从 http://xyz.com?credentials=abc 下载此文件
到目前为止,ASPX 页面执行以下操作:
- 验证凭据
- this.Response.ContentType = "application/octet-stream";
- this.Response.BinaryWrite(binaryReader.ReadBytes(1024));
从 WinForms 应用程序下载此文件数据的最佳方式是什么?
请您参考如下方法:
最简单的方法是使用 WebClient :
WebClient wc = new WebClient();
wc.DownloadFile(url, filename);
(要么不在 UI 线程中启动它,要么使用异步版本。您不希望 UI 线程在下载时阻塞。)
