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; 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>
I can't access the POST data using $apr object. But I can access the same POST data if I replace $apr with $page.
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

Replies are listed 'Best First'.
Re: Problem with accessing POST data through Apache::Request
by Khen1950fx (Canon) on Aug 14, 2006 at 08:56 UTC
    I would switch from using the new() class method to the instance() class method:

     my $apr= Apache::Request->instance(shift);

    See:

    instance()

    See, also, Randy Kobes' article on mod_perl:

    Accessing HTML Form Fields

      I think instance is a decent fix but it is necessary because of the mixing of Apache::Request and CGI. Any interesting test would be to swap the these two lines:

      my $page = new CGI; my $test=$apr->param('school');
      If you put the $apr->param request before CGI, then it should work (since CGI would not have had the chance to consume the POST). But ideally, I wouldn't mix Apache::Request with CGI.

      -derby
        Thanks for the input, Derby. Putting the $apr->param request before CGI was a great idea!

      Thanks.
      I tried with ,
      my $apr= Apache::Request->instance(shift);
      but no luck!

      But if I send the Post data along with the URL, it works fine. Even with Apache::Request->new(shift)
      ( i.e http://myhost/perl/test.pl?school=test )
      Can a configuaration issue cause this type of an errornuos situation? Here is my Apache mod_perl configuration for your information.

      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>

        Can a configuaration issue cause this type of an errornuos situation? Here is my Apache mod_perl configuration for your information.

        Probably not ... I think your issue is mixing CGI with Apache::Request. You new CGI is consuming the post before Apache::Request can read it. I would suggest using either CGI or Apache::Request but not both. If you want to use both, place the new CGI after all your $apr->param calls.

        And ... send the Post data along with the URL ... it's no longer POST data when you do that ... that makes it GET data

        -derby