IE 无法通过 WebSphere 提供的 SSL 下载文件

发布于 2024-11-18 07:24:41 字数 963 浏览 3 评论 0原文

IE 7 和当用户尝试通过 https 下载 csv 文件时,8.0.8 都会抛出错误。

Internet Explorer 无法下载 downloadPage.jsf。 Internet Explorer 无法打开该网站。请求的站点不可用或无法找到。请重试

我读到了 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();

IE 7 & 8 both throw an error when users attempt to download a csv file over https.

Internet Explorer cannot download downloadPage.jsf. Internet Explorer was not able to open this internet site. The requested site is either unavailable or cannot be found. Please try again

I read about the issues IE has in relation to caching so I changed the response to allow public caching. See this issue: IE cannot download foo.jsf. IE was not able to open this internet site. The requested site is either unavailable or cannot be found

response.setHeader("Pragma", "public");
response.setHeader("Cache-Control", "public");

But I am still getting this error.

Any ideas what else could be causing the issue? Here's the complete snippet:

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();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

朱染 2024-11-25 07:24:41

当响应中包含 cookie 时,WebSphere 似乎会自动添加 Cache-Control:no-cache=set-cookie 响应标头。 IE8&较老的人在通过 SSL 下载时不喜欢这样。

根据此 IBM Developerworks 论坛帖子,有两个可能的修复方法:

  1. 为WebSphere 中的HTTP 传输通道添加自定义响应标头CookiesConfigureNoCache:false(默认情况下为true)。

    response.setHeader("CookiesConfigureNoCache", "false");             
    
  2. 添加 cookie 之后显式设置 Cache-Control 标头,这将覆盖 WebSphere 设置的标头。

    response.addCookie(...);
    响应.addCookie(...);
    ...
    response.setHeader("缓存控制", ...);
    

It appears that WebSphere automatically adds Cache-Control:no-cache=set-cookie response header when cookies are included in the response. IE8 & older do not like this when downloading over SSL.

There are two possible fixes as per this IBM Developerworks forum thread:

  1. Add the custom response header CookiesConfigureNoCache:false for HTTP transport Channel in WebSphere (it's true by default).

    response.setHeader("CookiesConfigureNoCache", "false");             
    
  2. Explicitly set the Cache-Control header after cookies are being added, this will override the WebSphere-set one.

    response.addCookie(...);
    response.addCookie(...);
    ...
    response.setHeader("Cache-Control", ...);
    
何其悲哀 2024-11-25 07:24:41

我用IE8也遇到同样的问题。
我对我的代码做了一些小改动。

Response.ClearHeaders(); //需要,否则“no-cache: set-cookie”就在那里,必须删除它

Response.addHeader("Cache-Control", "private");

I had the same issue with IE8.
I made small changes to my code.

Response.ClearHeaders(); //needed, otherwise "no-cache: set-cookie" was there, had to get rid of it

Response.addHeader("Cache-Control", "private");

你没皮卡萌 2024-11-25 07:24:41

当应用程序服务器配置为使用 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));

Had the exact same issue when the app server was configured to use SSL. The trick for me to get it working after the https was turned on:

   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));
溺孤伤于心 2024-11-25 07:24:41

我认为您在缓存方面走在正确的道路上:

这篇知识库文章可能会帮助您,
Internet Explorer 无法从 SSL 网站打开 Office 文档

此 Stack Overflow 问题中提到: 无法在 IE 中打开 xls 文件

I think you are on the right track with caching:

This knowledge base article may help you,
Internet Explorer is unable to open Office documents from an SSL Web site

Mentioned in this Stack Overflow question: Cannot open xls file in IE

彼岸花ソ最美的依靠 2024-11-25 07:24:41

我也遇到了同样的问题。
设置“Content-Disposition”和“Content-Type”后,添加此代码。

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");

I hade the same problem.
After set "Content-Disposition" and "Content-Type", add this code.

Java code

// 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 code

// 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");
晨曦÷微暖 2024-11-25 07:24:41

这是我在 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 );

Here's what I've done in my PHP code:

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 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文