toadi has asked for the wisdom of the Perl Monks concerning the following question:

hello,

Again I have a post question :)
In my Re: Re: Re: Re: Receiving POST yesterday I wrote a quick hack to demonstrate what I want. That worked. But today I'm trying to rewrite the script to get it a bit better and I'm working to a good and secure script. But I stumbled on a strange problem.

My new send script:
use strict; use LWP::UserAgent; my $ua = new LWP::UserAgent; $ua->agent("PlanetXML/0.1 " . $ua->agent); my $req = new HTTP::Request POST => 'http://geert.dia.pi.be/cgi-bin/xm +lreceive.cgi'; $req->content_type('text/xml'); my $content = slurp("/export/home/geert/xml/XMLS/PXMLStatusMessage.xml +"); $req->content($content); my $res = $ua->request($req); if ($res->is_success) { print $res->content; } else { print "Error\n"; } sub slurp { local $/ = undef; local *X; open X, $_[0] or die "Can't open $_[0]: $!"; my $slurp = <X>; close X or die "Can't close $_[0]: $!"; $slurp; }

Yesterdayfor fast testing purposes I used:
$content=<<END; <xml> </xml> END
To get the contents of my xml.

The receiving script in my former post : http://www.perlmonks.org/index.pl?node_id=97650&lastnode_id=6364 received keywords as param, so I could get the xml as value. But when using my new send script, it doesn't send the param keywords?? But a part of my xml as param?



--
My opinions may have changed,
but not the fact that I am right

Replies are listed 'Best First'.
Re: Yet another POST question
by toadi (Chaplain) on Jul 19, 2001 at 15:53 UTC
    Is solved my problem with a quick workaround :)
    use strict; $|=1; use CGI; my $q = new CGI; my %in = map { $_ => $q->param($_) } $q->param; print $q->header; foreach my $key (keys %in) { print $key.$in{$key}; }
    But I still don't know why it works when giving a sample input straight into and scalar. And when slurping the the file in a scalar it doesn't work anymore and behaves different?

    --
    My opinions may have changed,
    but not the fact that I am right

Re: Yet another POST question
by mitd (Curate) on Jul 20, 2001 at 01:18 UTC
    You are not setting up up your 'POST' REQUEST correctly. There is no PARAM keyword being sent.

    Update: correctly should be incorrectly doh!

    Try this:

    
    ...
    use LWP::UserAgent;
    #use Commom module for convienence
    use HTTP::Request::Common
    
    my $ua = LWP::UserAgent->new();
    
    $content<<EOC;
    <xml>
    <name>mitd</name>
    </xml>
    EOC
    
    $ua->request( POST, 'http://somewhere.com/somexml.cgi',
    [XML=>$content]);
    
    
    

    At receiving end something like this:

    
    my $xmaldoc = $q->param('XML');
    

    xmldoc now contains your .. well .. xml document.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

      yes i know it's not setup correctly :) But I don't know what sort of param is going to be transmitted from the other end. But I sorted that out now with my receiving program. But thanx anyway to post the correction!

      --
      My opinions may have changed,
      but not the fact that I am right