Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify POST request in mod_perl2

Does anyone know how to access/modify the POST request data using mod_perl2. IN GET method one can get/set the request QUERY string:

  $args      = $r->args();
  $prev_args = $r->args($new_args);

How to get/set the request QUERY string in POST method ?

like image 648
user372001 Avatar asked Jun 21 '10 09:06

user372001


2 Answers

Get POST parameters with Apache2::Request::param.

To set, first get an APR::Request::Param::Table object from the body method. Rebless it into an APR::Table object, then use its methods to manipulate the data.

like image 190
daxim Avatar answered Oct 04 '22 22:10

daxim


I use this mod_perl2 code snippet to successfully parse out a form's field value submitted via POST method:

use CGI;

my $req = CGI->new($r);
my $field_value = $req->param('form_field');

If you don't use CGI; as illustrated above, and instead, use the following code:

my $req = Apache2::Request->new($r);
my $field_value = $req->param('form_field');

You'll probably succeed in GET method. However, while getting request via POST method, in my case, I got into infinite loop of some king of 'prefetching filter.c(270) error' and the request will never return.

like image 24
hko19 Avatar answered Oct 04 '22 22:10

hko19