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

I'm migrating my CGI scripts over to Apache::Registry and mod_perl, and I'm having a problem with a paticular script that uses a POST to accept data.

I've narrowed down the problem as follows:

#!/usr/bin/perl my $posteddata; $posteddata .= $_ while (<>); print << "EOF"; Content-Type: text/plain $posteddata EOF

Under normal CGI this code echos back whatever is POSTed to it. When I run it under mod_perl and Apache::Registry, $posteddata comes up empty.

Does Apache::Registry pass in POSTed data in a different way? Is there a way to get your hands on the request object within a CGI script running under Apache::Registry? (so that I may manually read() the POSTed data from it?)

Replies are listed 'Best First'.
Re: Apache::Registry and POSTs
by submersible_toaster (Chaplain) on Jun 02, 2003 at 03:10 UTC

    How have you configured apache to call your CGI? If you are for example using Apache::Registry as a perl-handler then you might have more luck using the apache request object. Scripts launch by Apache::Registry get passed this as their first (subroutine) arg.

    #!/usr/bin/perl my $request = shift; $request->send_http_header('text/plain'); $request->print( $request->content() );
    Which I have not tested but should do the trick for you. Read up on the CPAN about Apache modules.

    I can't believe it's not psellchecked
Re: Apache::Registry and POSTs
by perrin (Chancellor) on Jun 02, 2003 at 03:21 UTC
    There's an example of reading POST data with mod_perl here.
Re: Apache::Registry and POSTs
by Juerd (Abbot) on Jun 02, 2003 at 05:32 UTC

    $posteddata .= $_ while (<>);

    Why are you using magical <ARGV>? This is a security bug. Try using your line with in a CGI script and fetch it as follows: http://foo/bar.cgi?/etc/passwd

    Use STDIN, not ARGV. (Note: <> is a shorthand for <ARGV>)

    And if you want to slurp, locally set $/ to undef and DO slurp:

    my $posteddata = do { local $/; readline *STDIN; };

    A more correct way of getting post contents is my $posteddata = $r->content;, where $r is the Apache object, as pointed out by others. By the way: get into the habit of using strict. This is very important in mod_perl, since if you don't clean them yourself, global variables are not destroyed in between requests.

    Content-Type: text/plain

    This only works if you have mod_perl configured to interpret headers.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }