开发者

IE cannot download files over SSL served by WebSphere

开发者 https://www.devze.com 2023-03-17 08:54 出处:网络
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.

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"开发者_C百科);
response.getOutputStream().write(contentBytes);
context.responseComplete();


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


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


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


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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号