Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

crossposted at stackoverflow here.

This has got to be something silly I'm doing wrong. It's such a newbie type problem.

The original script is something that sits and waits for a 3rd party to connect and POST some xml to it, it takes that xml, does some validation, and stores it in a db. That part is fine. The problem is my response. I'm trying to use the header() function from CGI and it's just not behaving. It comes up blank. Obviously I could just do this manually and just print the header string, but now I'm really curious why this is behaving so strangely.

Here is a stripped down test version of the cgi script:

#!/perl/bin/perl use strict; use warnings; use Data::Dumper::Names; use CGI qw(:standard); use Apache2::Connection (); use Apache2::RequestRec (); $| = 1; # Grab the request object provided by mod_perl. # our $request_obj = shift; our $connection = $request_obj->connection; our $remote_ip = $connection->client_ip(); my $cgi = CGI->new($request_obj->args()); print STDERR Dumper($cgi); my $input = $cgi->param('POSTDATA'); print STDERR Dumper($input); my $cgi_header = $cgi->header(); print STDERR Dumper($cgi_header); #my $cgi_full_header = $cgi->header(-type => 'application/xml', -statu +s => '400 Bad Request' ); my $cgi_full_header = $cgi->header(-type => 'application/xml'); print STDERR Dumper($cgi_full_header); my $q = CGI->new({}); print STDERR Dumper($q); my $q_header = $q->header(); print STDERR Dumper($q_header); #my $q_full_header = $q->header(-type => 'application/xml', -status => + '400 Bad Request' ); my $q_full_header = $q->header(-type => 'application/xml' ); print STDERR Dumper($q_full_header); exit;

And the output:

$cgi = bless( { '.r' => bless( do{\(my $o = '94118860562256')}, 'Apach +e2::RequestRec' ), 'param' => { 'POSTDATA' => [ 'test' ], 'XForms:Model' => [ 'test' ] }, 'use_tempfile' => 1, '.fieldnames' => {}, '.charset' => 'ISO-8859-1', 'escape' => 1, '.parameters' => [ 'XForms:Model', 'POSTDATA' ] }, 'CGI' ); $input = 'test'; $cgi_header = ''; $cgi_full_header = ''; $q = bless( { '.parameters' => [ 'XForms:Model', 'POSTDATA' ], 'escape' => 1, '.fieldnames' => {}, '.charset' => 'ISO-8859-1', 'use_tempfile' => 1, '.r' => bless( do{\(my $o = '94118860562256')}, 'Apache2 +::RequestRec' ), 'param' => { 'POSTDATA' => [ '' ], 'XForms:Model' => [ '' ] } }, 'CGI' ); $q_header = ''; $q_full_header = '';

And here is the simple test script I'm using to send the POST.

#!/perl/bin/perl use strict; use warnings; use DBI; use URI; use LWP::UserAgent; use Data::Dumper::Names; my $ua = LWP::UserAgent->new; $ua->max_size( 131072 ); $ua->agent('test_xml_pusher'); $ua->ssl_opts(verify_hostname => 0); my $url = URI->new; $url->scheme('https'); $url->host('xxxxxxxxxxxxxxxxxxxxxxxxx'); $url->port(443); $url->path_segments('test.cgi'); # Yes, I know... it's not valid xml... don't care for the purposes o +f this test. # my $xml = 'test'; my $response = $ua->post( $url, Content => $xml, 'Content-Type' => 'ap +plication/xml' ); print Dumper($response); my $status_line = $response->status_line; print Dumper($status_line); my $content = $response->content; print Dumper($content);

So why is $cgi_header empty? And why does $q end up being a reference to the same thing as $cgi even though I tried initializing it as my $q = CGI->new({});? (I also tried empty quotes instead of empty brackets.)

Any thoughts?


My environment is a centos 7 server running apache httpd 2.4.34 with mod_perl 2.0.11 and perl 5.22.4. (httpd is installed from from SCL, but perl and mod_perl are installed from source.)


In reply to mod_perl and CGI behavior by naChoZ

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-06-18 22:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.