Internet Explorer 显示 save/open 文件的乱码?
Internet explorer shows gibberish for save/open file?
我有这个从服务器下载文件的 C# 代码:
public static void DownloadBinaryFile(byte[] _ByteArray, string fullfileName)
{
fullfileName = "רועי.pdf"; //"Royi.pdf" in hebrew
System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fullfileName);
System.Web.HttpContext.Current.Response.BinaryWrite(_ByteArray);
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.End();
}
注意文件名有一个固定值(用于测试)。
当我点击一个按钮时:
我确实在 FIDDLER 中看到了正确的名称:
并且 Chrome 确实 显示了要保存的正确文件名:
但是 Internet Explorer 显示乱码:
附加信息:
IE 11,windows 7 64 位,边缘:
页面编码:
问题:
为什么文件名显示为乱码,我该如何解决?
因为您不能在 Content-Disposition 中使用非 ASCII 字符而不进行额外的转义。参见 http://greenbytes.de/tech/webdav/rfc6266.html#disposition.parameter.filename。
我有这个从服务器下载文件的 C# 代码:
public static void DownloadBinaryFile(byte[] _ByteArray, string fullfileName)
{
fullfileName = "רועי.pdf"; //"Royi.pdf" in hebrew
System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + fullfileName);
System.Web.HttpContext.Current.Response.BinaryWrite(_ByteArray);
System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream";
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.End();
}
注意文件名有一个固定值(用于测试)。
当我点击一个按钮时:
我确实在 FIDDLER 中看到了正确的名称:
并且 Chrome 确实 显示了要保存的正确文件名:
但是 Internet Explorer 显示乱码:
附加信息:
IE 11,windows 7 64 位,边缘:
页面编码:
问题:
为什么文件名显示为乱码,我该如何解决?
因为您不能在 Content-Disposition 中使用非 ASCII 字符而不进行额外的转义。参见 http://greenbytes.de/tech/webdav/rfc6266.html#disposition.parameter.filename。