别人访问下载接口
//post 请求报文体的接收方式
HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
System.IO.Stream inputStream = HttpContext.Current.Request.InputStream;
System.Text.Encoding encoding = HttpContext.Current.Request.ContentEncoding;
System.IO.StreamReader streamReader = new System.IO.StreamReader(inputStream, encoding);
string json = streamReader.ReadToEnd();
//得到错误信息
TH.SampleAccept.ServiceImpl.ResData res = daSErvice.GetPDFFile(json, context);
if (res.StatusCode == 200)
{
string fullPath = context.Server.MapPath("~///") + res.FilePaths.FileName;
string fileName = Path.GetFileName(fullPath);
FileInfo fileinfo = new FileInfo(fullPath);
context.Response.Clear(); //清除缓冲区流中的所有内容输出
context.Response.ClearContent(); //清除缓冲区流中的所有内容输出
context.Response.ClearHeaders(); //清除缓冲区流中的所有头
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.AddHeader("Content-type", "text/html;charset=UTF-8");
context.Response.ContentEncoding = System.Text.Encoding.UTF8; //获取或设置输出流的 HTTP 字符集
context.Response.Buffer = true; //该值指示是否缓冲输出,并在完成处理整个响应之后将其发送 filename* = UTF-8''"+name
//context.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes(fileName)));
context.Response.AddHeader("Content-Length", fileinfo.Length.ToString());
context.Response.AddHeader("Content-Transfer-Encoding", "binary");
context.Response.ContentType = "application/unknow"; //获取或设置输出流的 HTTP MIME 类型
context.Response.TransmitFile(fullPath);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界