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

I need quick help writing the syntax to pass a hash to an HTTP post
use LWP::UserAgent; use HTTP::Request::Common; %myhash;#i have a hash of parameters I need to post $userAgent = LWP::UserAgent->new; $response = $userAgent->request(POST 'http://foo.bar', Content_Type => 'form-data', Content => %myhash #I need to post the hash, not sure of the syntax );
Thanks.

Replies are listed 'Best First'.
Re: Syntax problem LWP Post hash
by twotone (Beadle) on Jun 03, 2009 at 18:22 UTC

    Here's how I do it:

    use strict; use LWP::UserAgent; my $url = 'http://foobar.com'; my %postdata = (key => 'value', key2 => 'value2'); my $ua = LWP::UserAgent->new; my $response = $ua->post($authorize_url,[%postdata]); if ($response->is_success) { print $response->content; } else { print "Post Failed!\n"; }
Re: Syntax problem LWP Post hash
by ccn (Vicar) on Jun 03, 2009 at 17:48 UTC
      I've actually looked at two of those three references you provided. I have checked the other one now too, but still fail to see an example of passing an exiting hash to a post. Let me apologize that I am a perl beginner and perhaps I am just missing it. Is there an easy way of doing it at all?