c# - 将 Response.OutputStream 保存到文件夹
问题描述
我有一个HttpWebRequest
当前正在下载文件,但我想停止下载并将文件保存在文件夹中。
webRequest.Method = "GET";
webRequest.Credentials = CredentialCache.DefaultCredentials;
webRequest.ContentType = "text/xml;charset=UTF-8";
using (var webResponse = webRequest.GetResponse())
using (var webStream = webResponse.GetResponseStream())
{
if (webStream != null)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=\"test.pdf\"");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
webStream.CopyTo(Response.OutputStream);
Response.Flush();
Response.End();
}
}
我尝试将 ContactType 更改为Response.ContentType = "application/x-download";
并添加Response.TransmitFile
,但文件仍在下载。
解决方案
推荐阅读
- php - 删除表数据后 PHP mysqli->rollback() 不起作用
- python-3.x - Python 3 - 二进制模式下的 open() 不会创建文件名中包含特殊字符的文件
- javascript - Node.js:从该应用安装的节点模块中获取应用文件夹的路径
- javascript - 如何使用触摸事件跟踪手指运动
- android - Fabric Crashlytics 卡在构建和运行上 - IDE 错误
- javascript - 如何在服务器的 p5.js 中正确加载图像
- android - 如何使用 LiveData + Retrofit 在 30 分钟内缓存数据?
- git - 正确处理 Jenkins 管道中每个分支的单独凭据
- r - 有没有办法使用 rpy2(在 jupyter notebook 中)修复包 'afex' 的安装?
- github - github 可以有条件地对过时的分支执行状态检查吗?