IE 7&当用户试图通过https下载csv文件时,8都会抛出错误。
Internet Explorer无法下载downloadPage.jsf。Internet Explorer无法打开此Internet站点。请求的站点不可用或找不到。请重试
我读到IE与缓存有关的问题,所以我更改了响应以允许公共缓存。请参阅此问题:IE无法下载foo.jsf。IE无法打开此网站。请求的站点不可用或找不到
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "public");
但我还是犯了这个错误。
有没有其他想法可能导致这个问题?以下是完整的片段:
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
response.setContentType("text/plain");
response.setHeader("Content-Disposition", "attachment; filename="" + browserFilename + """);
response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "public");
response.getOutputStream().write(contentBytes);
context.responseComplete();
当响应中包含cookie时,WebSphere会自动添加Cache-Control:no-cache=set-cookie
响应标头。IE8&较老的用户不喜欢通过SSL进行下载。
根据这个IBM Developerworks论坛线程,有两种可能的修复方法:
-
在WebSphere中添加HTTP传输通道的自定义响应标头
CookiesConfigureNoCache:false
(默认情况下为true(。response.setHeader("CookiesConfigureNoCache", "false");
-
添加cookie后,显式设置
Cache-Control
标头,这将覆盖WebSphere设置的标头。response.addCookie(...); response.addCookie(...); ... response.setHeader("Cache-Control", ...);
我在IE8上遇到了同样的问题。我对代码做了一些小的更改。
Response.ClearHeaders((//需要,否则"没有缓存:设置cookie",必须在中删除它
Response.addHeader("缓存控制"、"私有"(;
在应用程序服务器配置为使用SSL时也出现了完全相同的问题。https打开后我让它工作的诀窍:
string attachment = "attachment; filename=" + rptName + ".xls" + "";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.AddHeader("Cache-Control", "private, max-age=1");
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(1));
我认为您在缓存方面走在了正确的轨道上:
这篇知识库文章可能会帮助你,Internet Explorer无法从SSL网站打开Office文档
在这个堆栈溢出问题中提到:无法在IE 中打开xls文件
我也遇到了同样的问题。在设置"内容处置"one_answers"内容类型"后,添加此代码。
Java代码
// IE requires these three lines, exactly like this
response.setHeader("CookiesConfigureNoCache", "false");
response.setHeader("Pragma","private,no-cache");
response.setHeader("Cache-control","private,no-store,no-cache,max-age=0,must-revalidate");
PHP代码
// IE requires these three lines, exactly like this
header("CookiesConfigureNoCache: false");
header("Pragma: private,no-cache");
header("Cache-control: private,no-store,no-cache,max-age=0,must-revalidate");
以下是我在PHP代码中所做的:
header( "HTTP/1.0 200 OK" );
header( "Content-Disposition: inline; filename=$path" );
header( "Content-Type: attachment; application/pdf" );
header( "Content-Length: $info[7]" );
header( "Cache-Control: no-store, no-cache" ); // IE 8 requires these two lines, exactly like this
header( "Pragma: private" ); // IE 8 requires these two lines, exactly like this
readfile( $tmpfile );