浏览器下载图片的方法,修改报文来实现。

public class DownloadTest : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
string f1 = context.Request["f1"];//文件流

//指定为下载操作
context.Response.ContentType = "application/octet-stream";
//附加头信息,表示保存文件时的文件名
context.Response.AddHeader("Content-Disposition", "attachment; filename=""+f1+"";");

//输出文件
context.Response.WriteFile(context.Request.MapPath(f1));

}

public bool IsReusable
{
get
{
return false;
}
}
}

原文地址:https://www.cnblogs.com/ansheng/p/4772930.html