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

Hi,
I'm having a problem with accessing POST data through Apache::Request object. here is my code snippet which accesses the request data.

use Apache::Request; my $apr = Apache::Request->new(shift); my $test=$r->param('POST_PARAM_NAME');

I can't access the POST data by param. But I can access the same POST data if I replace Apache::Request with CGI.
I am running my applications in Apache 1.3, which is mod-perl enabled.
I am sort of a beginner to Perl. Can anybody help me with this??
Thanks.
Thilani

20060808 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips

  • Comment on Problem with getting POST request data with Apache::Request object
  • Download Code

Replies are listed 'Best First'.
Re: Problem with getting POST request data with Apache::Request object
by dorward (Curate) on Aug 08, 2006 at 11:16 UTC

    I suggest you have a look at A Simple mod_perl Content Handler. Mod_perl is a fairly complicated beast, and using it isn't quite as simple as the synopsis of Apache::Request may suggest.

Re: Problem with getting POST request data with Apache::Request object
by imp (Priest) on Aug 08, 2006 at 12:17 UTC
    Please post a minimal working example that demonstrates the problem you are having. The reason for providing the minimal working example is that without it we will sometimes assume things about the other areas of the code that are incorrect.

    Also, some additional context information would help. Are you running this as a script using Apache::Registry, or as a separate apache module? Please provide the relevant portion of your apache config file. For example:

    <Location /foo> SetHandler perl-script PerlHandler Apache::Registry Options +ExecCGI PerlSendHeader On </Location>

      Here's the full program that i was trying to run and the HTML content.

      use Apache::Request; use CGI; my $apr= Apache::Request->new(shift); my $page = new CGI; my $test=$apr->param('school'); print $page->header(); print("Post Data " . $test);

      HTML content

      <html> <head></head> <body> <form method=Post action='test.pl' > <input type=text name='school' value='test'> <input type=submit value='Ok'> </form> </body> </html>

      mod_perl configuration in http.conf

      Alias /perl/ /usr/local/apache/cgi-bin/ PerlModule Apache::Registry <Location /perl/> SetHandler perl-script PerlHandler Apache::Registry Options +ExecCGI PerlSendHeader On allow from all </Location>

      Apache version is 1.3.
        Try this instead, see what happens:
        my $test = $page->param('school');

        ---
        It's all fine and dandy until someone has to look at the code.
Re: Problem with getting POST request data with Apache::Request object
by cdarke (Prior) on Aug 08, 2006 at 10:09 UTC
    Where is $r coming from ($r->param)?
    Should that be $apr ($apr->param)?
      I am sorry my $test=$r->param('POST_PARAM_NAME'); should be, my $test=$apr->param('POST_PARAM_NAME'); anyway, my original program has that correctly :). but still it doesn't work. Thilani
Re: Problem with getting POST request data with Apache::Request object
by Khen1950fx (Canon) on Aug 08, 2006 at 11:45 UTC
    I have a question: Has your script worked before or not at all? If it's worked before, then you might want to convert the POST request into a GET request. I'm not an expert on Apache, but I remember that you can only read POST data from a socket once, so you have to store the data somewhere, for example, by switching the the request method from POST to GET and then storing the POST data in a query string. See:

    Convert a POST Request into a GET Request

      Thanks for the replies. It did not work at all.(at least once)

      But I have a code (uses Apache::Request to get data) which works fine with other machines, and not in mine.

      is it possible a configuration issue to cause this type of a situation??



      Thilani