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

Hi Monks!
I am having a nightmare here trying to use print "Location: $request\n\n";
This code generates a
CGI Error The specified CGI application misbehaved by not returning a complete s +et of HTTP headers.
. The weird thing is that only happens when I type a few paragraphs inside a text area from this form, (There is no print header like, print header(); in this code. I tried to filter newline, carriage returns, but after a few entries in the text area fields it gives me the CGI Error.
Any help on that? Another question is if "Location" has a limit on number of parameters that can be passed to.
May be someone has been through this before.
Thanks!!!

Replies are listed 'Best First'.
Re: Location: Issue
by jdporter (Paladin) on Jul 13, 2007 at 20:13 UTC

    I highly recommend you use the CGI module (or one like it) to generate your response. The CGI method for this is redirect. The CGI doc advises that you not call header as well, since Location: is itself a HTTP header, and is the only one you need, after the HTTP Response status line.

    A word spoken in Mind will reach its own level, in the objective world, by its own weight
Re: Location: Issue
by saintly (Scribe) on Jul 13, 2007 at 18:06 UTC
    There's not a lot of help here for people trying to figure out what went wrong with your program... The thing after 'Location: ' has to be a URL, and must be properly formatted as an absolute URL. That means spaces and most funny characters must be URL-escaped. If you're not printing headers (and you probably should, so you know where they're coming from. At the very least, you should print a Content-type in some form or other), then Apache is probably looking at the output of your script to see if the first things you're saying look like HTTP headers. If so (and 'Location:' is an HTTP header), then it will expect them to be properly formatted. If you're not intending to redirect the client, then perhaps you should print a couple newlines first. That might get Apache to believe you're not going to print any, and it may end up as a text/plain page in the browser.