Rodster001 has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

This posting is somewhat of a continuation of this thread.

To summarize, when the attachment header is sent to IE choosing "save" from the dialogue box works but "open" sometimes (depending on the system) results in the file "not found". This has something to do with the cache in IE (I believe).

The update is that Google's analytics site has a pdf export option for each of its report pages. This works flawlessly (choosing open or save when prompted by the dialogue box). I am guessing that Google is sending something else in the header which I am not that is making theirs work. But, since the site is secure and requires a form based login I can't easily see the header they are sending (by telneting to port 80 for example).

This is my code snippet that is not working.

use CGI; my $f; open (OUT,"somefile.pdf") or print STDERR "Can't open $!"; while (<OUT>) { $f .= $_; } close (OUT); my $l = length($f); print CGI->header( -type =>"application/octet-stream", -expires=> '+3d', -charset=>'utf-7', -Content_length => $l, -attachment => "example.pdf", ); print $f; exit;
Any ideas? Thanks!

Replies are listed 'Best First'.
Re: HTTP Attachment Header
by ikegami (Patriarch) on Jan 16, 2009 at 19:37 UTC

    This has something to do with the cache in IE (I believe).

    Did you check your file associations? (c.f. Re: Content-Disposition... odd behavior in IE)

    I can't easily see the header they are sending

    Right-click, View Page Info in FF. There's also the Live HTTP Headers plugin.

      Yes. My example is sending a PDF and Google's site is also sending PDFs. So, both are opening the same helper app (Acrobat). The IE dialoge box that opens on their site and produced by my example appear the same (except for the file name and the document size).

      Like I said... maybe there is something else in the header, but everything I have tried up to now doesn't fix the problem.

        The IE dialoge box that opens on their site and produced by my example appear the same (except for the file name and the document size).

        That doesn't preclude an association problem. May I see the command string of the association?

        Like I said... maybe there is something else in the header

        The header you were sending is fine. You've demonstrated this yourself. (And that means this isn't even a Perl problem!)

Re: HTTP Attachment Header
by Corion (Patriarch) on Jan 16, 2009 at 19:41 UTC

    Why not look (using Wireshark) what Google sends? Then just replicate that and you're set?

      Thanks Corion, your suggestion pointed me in the right direction.

      I compared the two response headers (my test and Google's) and there were additional headers being sent by the web server I was using (that were not in the script).

      Apache's config file had several "header set" directives added to prevent cacheing (that I was unaware of). I'm glad the problem is solved, but I was barking up the wrong tree! If I hadn't looked at the headers the way you suggested... well, I'd probably still be pulling my hair out!

      At any rate, thanks for the help! Cheers!

        if you make it nph, apache won't add headers
      Something like this would probably do the trick. But their download links (http://www.wireshark.org/downloads/win32/wireshark-setup-1.0.5.exe) are broken. Do you know of any other good network protocol analyzers?

      Update: Found it on Sourceforge... I'll post my results in a bit. Thanks!