【问题标题】:IE cannot download files over SSL served by WebSphereIE 无法通过 WebSphere 提供的 SSL 下载文件
【发布时间】:2011-07-04 15:38:02
【问题描述】:

当用户尝试通过 https 下载 csv 文件时,IE 7 和 8 都会引发错误。

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

我阅读了 IE 与缓存相关的问题,因此我更改了响应以允许公共缓存。看到这个问题: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");

但我仍然收到此错误。

您知道还有什么可能导致该问题吗?这是完整的 sn-p:

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

【问题讨论】:

  • 虽然可以在普通的 http 上工作?
  • 目前我不确定,在非 SSL 模式下的应用程序有问题。
  • 这篇文章对我帮助很大。感谢所有贡献的人!

标签: internet-explorer jsf websphere download


【解决方案1】:

当响应中包含 cookie 时,WebSphere 似乎会自动添加 Cache-Control:no-cache=set-cookie 响应标头。通过 SSL 下载时,IE8 及更早版本不喜欢这样。

根据IBM Developerworks forum thread,有两个可能的修复:

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

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

    response.addCookie(...);
    response.addCookie(...);
    ...
    response.setHeader("Cache-Control", ...);
    

【讨论】:

  • 在所有 cookie 处理完成后设置 'Cache-Control' 标头是什么意思?我怎么知道所有的 cookie 处理都结束了?我可以在 servlet 中做吗?
  • @webdev - 是的,在 servlet 级别。
  • 很抱歉,我不确定如何知道 cookie 处理结束?
【解决方案2】:

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

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

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

    • 布莱恩,谢谢你的帖子。我更改了我的文件下载逻辑以匹配你的,它现在适用于有问题的 IE8 客户端。我不确定到底是哪一行/几行代码有所不同,但无论如何,谢谢!
    【解决方案4】:

    我认为你在缓存方面是正确的:

    这篇知识库文章可能会对您有所帮助, Internet Explorer is unable to open Office documents from an SSL Web site

    在这个 Stack Overflow 问题中提到:Cannot open xls file in IE

    【讨论】:

    • 还是没有运气。我在响应头中尝试了各种组合。它在应用程序的早期版本中运行良好。唯一的区别是响应中存在 2 个 Set-Cookie 项以及“Cache-Control: no-cache=set-cookie”。这个 no-cache=set-cookie 值会导致问题吗?
    • 我不确定“Cache-Control: no-cache=set-cookie”。但是看看palisade.plynt.com/issues/2007Mar/internet-cookies(标题为:Cookie 是否也存储在缓存中?)我认为这不会引起任何问题。是否与 IE 中的自定义安全设置有关?您是否在有额外限制的公司网络上运行 IE(也许试试 firefox)?
    • 是的,它在公司网络上,但在 Firefox、Chrome 和 IE9 中运行良好。
    • 另外,网络上的多个用户都在发生这种情况,所以不会是我们自己制作的任何自定义 IE 设置。
    • @Thomas Buckley 有趣的是你在代理服务器后面运行吗?
    【解决方案5】:

    我也遇到过同样的问题。 设置“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");
    

    【讨论】:

      【解决方案6】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-19
        • 2017-10-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多