From diagonally googling, it seems the "correct" mime type is "application/vnd.ms-excel" which you mention in the last paragraph but you have it wrong in the first. BTW, the above is for XLS files, there is a different mime type if your file is XLSX.
I am quite certain that Excel::Writer::XLSX you mentioned in your other post (Excel file in perl program) has nothing to do with this. Perhaps it is your browser or some antivirus or you got the mime type wrong.
The following script was taken from CGI's doc and works for me when accessing it with Firefox, albeit it does not ask me to save the file (specified with -attachment) but it opens the file with Libre Office. Note that CGI's doc mentions this:
Note that the default being ISO-8859-1 may not
make sense for all content types, e.g.
Content-Type: image/gif; charset=ISO-8859-1
In the above case you need to pass -charset => ''
to prevent the default being used.
The headers you mentioned you are receiving show that you have a charset after the mime type. Perhaps that confuses your browser.
Here is the script:
# mycgi.pl
use CGI;
my $cgi = CGI->new;
print $cgi->header(
-type => 'application/vnd.ms-excel',
#-nph => 1,
-expires => '+3d',
#-charset => 'utf-8',
-charset => '',
-attachment => 'foo.xls',
);
# you need a foo.xls in your local dir
open (IMAGE, '<', 'foo.xls');
print <IMAGE>;
close IMAGE;
And for those happy creatures who use Linux, here is a oneliner web server to check the above at http://localhost:8080:
while true; do { echo -ne "HTTP/1.1 200 OK\r\n"; perl mycgi.pl; } | nc
+ -l -k 8080; done
I guess you know this but you can open Firefox's Developer Tools and see what is received when you click the Network tab, including headers, cookies, etc. Check that first.
Update: if you want your browser to just save the file, then why don't you use the binary file mime type: application/octet-stream
bw, bliako |