gpt4 book ai didi

C# 下载文件 - BADRESPONSE : Invalid or unexpected token

转载 作者:太空宇宙 更新时间:2023-11-03 15:05:21 26 4
gpt4 key购买 nike

我正在调用这个直接方法,但是当我尝试下载文件时收到这个错误(路径是正确的并且经过测试):

[DirectMethod]
public void downloadFile(string fname, string ftype)
{
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
String Header = "Attachment; Filename=" + fname;
HttpContext.Current.Response.AppendHeader("Content-Disposition", Header);
System.IO.FileInfo Dfile = new System.IO.FileInfo(HttpContext.Current.Server.MapPath("CopyFiles\\" + ftype + "\\"+ fname));
HttpContext.Current.Response.WriteFile(Dfile.FullName);
HttpContext.Current.Response.End();
}

BADRESPONSE: Invalid or unexpected token

最佳答案

它只需要在 WriteFile() 之前 flush() :

[DirectMethod]
public void downloadFile(string fname, string ftype)
{
HttpContext.Current.Response.ContentType = "APPLICATION/OCTET-STREAM";
String Header = "Attachment; Filename=" + fname;
HttpContext.Current.Response.AppendHeader("Content-Disposition", Header);
System.IO.FileInfo Dfile = new System.IO.FileInfo(HttpContext.Current.Server.MapPath("CopyFiles\\" + ftype + "\\"+ fname));
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.WriteFile(Dfile.FullName);
HttpContext.Current.Response.End();
}

关于C# 下载文件 - BADRESPONSE : Invalid or unexpected token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43804857/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com