On Wed, 10 Sep 2008 09:07:38 +0200 Srebrenko wrote: > Hi list, > > I'm trying to use libapreq2/Apache2::Request to access the POST > body/payload under mod_perl2. According to the docs, one can > potentially use APR::Request::Parser custom/generic to achieve this. > What I'm trying to do is have Apache2::Request process POST payloads > with "text/xml" as Content-Type. > > Does anybody have an example on how to do this? > > TIA, > Srebrenko
Hopefully someone will respond who has experience with libapreq2's hook API. The below example (libapreq2 not used) which decodes JSON (not XML) may provide some insight or a temporary solution. use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::URI (); use Apache2::Const -compile => qw(M_POST); use JSON::XS qw(decode_json); if ($r->method_number() == Apache2::Const::M_POST) { if (my $ct = $r->header_in->{'Content-Type'}) { if ($ct =~ /\btext\/x-json\b/i) { if (my $len = $r->headers_in->{'Content-Length'}) { die 'read limit exceded' if $len > ((2**10) * 10); # 10K my $body = ''; $r->read($body, $len); if ($ct =~ /\bx-www-form-urlencoded\b/i) { $body = Apache2::URI::unescape_url($body); } my $json = decode_json($body); } } } }