Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: CGI header doesn't like me

by bobn (Chaplain)
on Sep 09, 2003 at 23:21 UTC ( [id://290220]=note: print w/replies, xml ) Need Help??


in reply to CGI header doesn't like me

when you do $cgi->header('test/plain'), it's not going to send a Content-Type header that the browser recognizes, hence the browser's offer to save the stream rather than just displaying.

As for the rest of your post, why would you send $cgi->header('test/plain'? what is it you're trying to aoomplish? what does "seems to work just about normal." mean? Your questions are not answerable if they are not comprehensible.

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

All code given here is UNTESTED unless otherwise stated.

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

    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.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://290220]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found