【发布时间】:2026-01-16 16:10:01
【问题描述】:
byte[] arrayofbyte = new System.Net.WebClient().DownloadData("http://pdfurl");
MemoryStream ms = new MemoryStream(arrayofbyte);
System.Web.HttpContext.Current.Response.ClearContent();
System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
System.Web.HttpContext.Current.Response.AddHeader("ContentType", "application/pdf; charset=utf-8");
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now.Ticks.ToString() + ".pdf" + ";");
System.Web.HttpContext.Current.Response.BinaryWrite(ms.ToArray());
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
【问题讨论】:
-
一般不欢迎纯代码问题。对你的问题添加一些解释怎么样?
-
您自己下载文件,然后转发?你确定 pdfurl 指向一个有效的文件,并且
ms有内容吗?