Thomas Buckley
Thomas Buckley

Reputation: 6056

IE cannot download files over SSL served by WebSphere

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

Upvotes: 8

Views: 20354

Answers (6)

Thomas Buckley
Thomas Buckley

Reputation: 6056

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

Upvotes: 9

Mena Fawzy
Mena Fawzy

Reputation: 9

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

Upvotes: 0

Bill
Bill

Reputation: 1

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

Upvotes: -1

Brian Wells
Brian Wells

Reputation: 1582

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

Upvotes: 2

Shari
Shari

Reputation: 49

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

Upvotes: 4

Alex KeySmith
Alex KeySmith

Reputation: 17101

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

Upvotes: 1

Related Questions