I have set up Apache 2.2 with mod_perl2 and libapreq2 for experimenting with processing posted XML.

Apache config:

LoadModule perl_module modules/mod_perl.so LoadModule apreq_module modules/mod_apreq2.so <IfModule negotiation_module> MultiviewsMatch Any </IfModule> <IfModule perl_module> PerlSwitches -T <Files *.pl> SetHandler modperl PerlResponseHandler ModPerl::Registry </Files> </IfModule>
A straightforward listener (DOCUMENT_ROOT/listen2.pl) which is supposed to dump the received info into a file:
use strict; use warnings FATAL => 'all', NONFATAL => 'redefine'; use Apache2::Const -compile => qw(HTTP_NO_CONTENT); use Apache2::Request(); use Apache2::RequestUtil(); use Data::Dumper; my $r = shift; my $req = Apache2::Request->new($r); $r->content_type('text/plain'); $r->status(Apache2::Const::HTTP_NO_CONTENT); my ($s, $m, $h, $D, $M, $Y) = (localtime($r->request_time))[0..5]; my $date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $Y+1900, $M+1, $D, $h, $m, $s ); { my $filename = '/var/tmp/listen'; open my $fh, '>>', $filename or die "could not open <$filename> fo +r append: $!"; syswrite $fh, $date."\n". $r->as_string."\n\n\n"; syswrite $fh, Dumper($req->body); close $fh; };
sample post request with LWP:
16:50 localhost:~> POST -c application/xml -PUSe 'http://localhost/lis +ten2/lol?foo=bar;quux' Please enter content (application/xml) to be POSTed: <lol>xml</lol> POST http://localhost/listen2/lol?foo=bar;quux User-Agent: lwp-request/2.07 Content-Length: 16 Content-Type: application/xml POST http://localhost/listen2/lol?foo=bar;quux --> 204 No Content Connection: close Date: Tue, 18 Apr 2006 14:51:00 GMT Server: Apache/2.2.0 (Unix) mod_apreq2-20051231/2.5.7 mod_perl/2.0.2 P +erl/v5.8.7 Content-Length: 0 Content-Type: text/plain Client-Date: Tue, 18 Apr 2006 14:51:00 GMT Client-Peer: 127.0.0.1:80 Client-Response-Num: 1
result in the listen file after the request:
2006-04-18 16:51:00 POST /listen2/lol?foo=bar;quux HTTP/1.1 TE: deflate,gzip;q=0.3 Connection: TE, close Host: localhost User-Agent: lwp-request/2.07 Content-Length: 16 Content-Type: application/xml HTTP/1.1 (null)
Now my two questions:
  1. Why is Dumper($req->body) empty/absent? I expect to see
    $VAR1 = '<lol>xml</lol> ';
    here.
  2. What is this string HTTP/1.1 (null) doing there in the middle? It's not part of the request.

In reply to Apache2::Request Apache2::RequestUtil - how to get at HTTP message body by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.