in reply to Changing the content type

Not sure if this is what you are looking for, but I use:

print $q->header(-type=>'text/xml'); print $q->header(-attachment=>'filename.xml');

where $q is a CGI object, to make the browser see a file filename.xml of type text/xml when opening my cgi script.

Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Replies are listed 'Best First'.
Re^2: Changing the content type
by Fletch (Bishop) on Jul 15, 2008 at 20:10 UTC

    FAIL. That prints two sets of headers.

    $ perl -MCGI -e 'my $q = CGI->new(); print $q->header(-type=>"text/xml +"); print $q->header(-attachment=>"filename.xml");' Content-Type: text/xml; charset=ISO-8859-1 Content-Disposition: attachment; filename="filename.xml" Content-Type: text/html; charset=ISO-8859-1

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Thank you for the correction. I'll check tomorrow when I'm at office if (a) the above code is really the one I use and (b) if our script shows the same problem!

      It is absolutely possible that we have put in production a program that duplicates the content-type and that Firefox accepts it without a warning using the first and discarding the second one.

      Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

        To add to Fletch's (rather unnecessarily vociferous) correction, the right way to do it is to pass both arguments to header at the same time.
        print $q->header(-type => 'text/xml', -attachment => 'filename.xml');
        If you're using a framework like CGI::Application, there are utility methods for keeping track of multiple headers and outputting them exactly once, so you don't have to keep track of lots of print statements and won't accidentally print two sets of headers.