SPUG: HTTP Headers

dancerboy dancerboy at strangelight.com
Tue Dec 11 18:52:28 CST 2001

There's actually a much more elegant solution.  Try sending these headers:

print "Content-type: application/download\n";
print "Content-Disposition: attachment; filename=foobar.doc\n\n";

BTW, you should be aware of one potential gotcha when downloading 
with IE:  IE normally sends *two* GET requests for each file that it 
downloads. (Actually, I think it's probably a HEAD request followed 
by a GET request, but for most CGI applications, the effect is the 
same.)  The first is sent by the browser proper, to find out what 
sort of file it is.  The second is sent by the "Download Manager" to 
do the actual download.

Usually, this doesn't cause any problems, but occasionally you may 
have reason to set up a system in which a download request also 
causes a state change on the server.  In this case, IE's download 
mechanism can cause problems.  E.g. I once set up a system, intended 
to be used by only a single client from a single location, that had a 
much-used "download everything that hasn't already been downloaded" 
feature.  It took me a while to figure out why this feature worked 
with Netscape but IE kept downloading empty files.  It was because, 
with IE, my script was seeing two download requests right in a row, 
so of course when it got the second download request, it believed 
that it had already downloaded everything it had, and had no new 
records to send.


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/

More information about the spug-list mailing list