in reply to Re: CGI header doesn't like me
in thread CGI header doesn't like me

Sorry, let me try again. I typed too fast on this node, hence the mistakes. The issue is that:

$cgi->header('text/plain');

Gives me the HTTP 200 (but doesn't show any subsequent print statements), while

$cgi->header('text/plain'), "\n";

Allows the page to render normally.


You asked what I am trying to do: I have many scripts that outputs to a text-file. Rather than reformatting for the web, I would like to just add code to the top like:

use CGI; $cgi->header('text/plain');

and have the text show up, just as it would if it had been giving output to screen.

Replies are listed 'Best First'.
Re: Re: Re: CGI header doesn't like me
by Anonymous Monk on Sep 10, 2003 at 00:27 UTC

    At the risk of being annoying, here is an example of my second pint

    use CGI qw/:standard/; my $cgi = new CGI; print $cgi->header('text/plain'); print "testing\n";

    I had believed that this would display simply "testing" within the browser window. That isn't the case -- it attempts to download the output -- but I haven't been able to figure out why, or how to change this behaviour

      what you have works on my system, using mozilla as the browser.

      http requires a blank line after headers, before the actual content. On my system, print $cgi->header('text/plain'); does that. You should run your program from the command line to see that that is happening on your system.

      On the other hand, the extra "\n" doesn't hurt anything.

      --Bob Niederman, http://bob-n.com

      All code given here is UNTESTED unless otherwise stated.

      I tried with the following code, and I got no problems:
      use CGI; my $cgi = new CGI; print $cgi->header('text/plain'); print <<HTML; <HTML> <BODY> HELLO HTML! </BODY> </HTML> HTML
      I got the following output:
      Content-Type: text/plain; charset=ISO-8859-1 <HTML> <BODY> HELLO HTML! </BODY> </HTML>
      HTML return code 200 means that the browser is happy with the stream but have no content to print, so the browser prints some debug message. Adding an extra return tells the browser to display the empty page.

      There was nothing wrong with the browser nor the code.