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

Dear Monkeys,

I am having some trouble with Apache::Request in a mod_perl app. According to the (somewhat sparse) documentation, Apache::Request's param method is supposed to behave just like CGI's, and return both GET (query string) and POST parameters. For GET it works fine, but for POST, it returns nothing at all. I know that the POST data is getting to the program properly, because if I instantiate a CGI object and use that, it works fine, per this simple test:

use strict; use warnings; ... sub test_p { my ( $self, $r ) = @_; # $r is an Apache::Request instantiated earlier my $q = CGI->new; $r->print('<p>Testing Apache::Request param method<p>'); $r->print('<pre>', Dumper( { map { $_ => $r->param($_) } $r->param } ), '</pre>' ); $r->print('<p>Testing CGI param method<p>'); $r->print('<pre>', Dumper( { map { $_ => $q->param($_) }$q->param } ), '</pre>'); return OK; }


Testing Apache::Request param method

$VAR1 = {};

Testing CGI param method

$VAR1 = {
          'Update.x' => '50',
          'Update.y' => '10',
          # and a bunch of other POST data
};


Any ideas?

Thanks,
Mike

Replies are listed 'Best First'.
Re: Apache::Request::param working for GET but not POST
by ikegami (Patriarch) on Feb 04, 2005 at 22:22 UTC

    I bet your CGI->new is sucking the POST parameters from the stream, readering them unavailable to Apache::Request. Unlike GET parameters, POST parameters can only be read once. (CGI reads both GET and POST parameters when new is called, and stores them in the returned object.)

      I bet you're right [id://ikegami], thanks. I will test it as soon as I get back into the office tomorrow and post an update.

      Update: You're right, [id://ikegami]. Once again, all my troubles are reduced to something really stupid. :)