Using a hash for the post data in LWP::useragent?

Discussion in 'Perl Misc' started by Andrew, Dec 5, 2003.

  1. Andrew

    Andrew Guest

    Does anyone know of a way to send the post data as reference to a hash
    instead of hardcoding the post data into the useragent request? I
    have tried using HTTP::Request::Common and Useragent request.

    for example:

    $ua->request(POST 'www.someurl.com',
    [ username => 'bob',
    host => 'localhost',
    other => '1',
    other2 => '2',
    other3 => '3',
    ]);

    I would like to to be able to use the same subroutine for multiple
    post data hashes by calling

    my %posthash = [ username => 'bob',host => 'localhost', other => '1',
    other2 => '2', other3 => '3']


    $ua->request(POST $url, \%posthash); # something like this



    anyone have any ideas on how to do this?
     
    Andrew, Dec 5, 2003
    #1
    1. Advertising

  2. Andrew wrote:
    > Does anyone know of a way to send the post data as reference to a
    > hash instead of hardcoding the post data into the useragent
    > request? I have tried using HTTP::Request::Common and Useragent
    > request.
    >
    > for example:
    >
    > $ua->request(POST 'www.someurl.com',
    > [ username => 'bob',
    > host => 'localhost',
    > other => '1',
    > other2 => '2',
    > other3 => '3',
    > ]);


    Assuming that is correct syntax, you are passing an array reference,
    not a hash reference.

    > I would like to to be able to use the same subroutine for multiple
    > post data hashes by calling
    >
    > my %posthash = [ username => 'bob',host => 'localhost',
    > other => '1', other2 => '2', other3 => '3']
    >
    > $ua->request(POST $url, \%posthash); # something like this


    Try this:

    my $postarrayref = [ username => 'bob',host => 'localhost',
    other => '1', other2 => '2', other3 => '3' ];

    $ua->request(POST $url, $postarrayref);

    (untested)

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Dec 5, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. La Jesus
    Replies:
    9
    Views:
    1,323
    Gunnar Hjalmarsson
    Oct 27, 2003
  2. Gaurav

    Problem using LWP::UserAgent

    Gaurav, Oct 2, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    239
    Tad McClellan
    Oct 2, 2003
  3. Rubel Kanubel

    Post radiobuttons (forms) using lwp-useragent

    Rubel Kanubel, Oct 12, 2003, in forum: Perl Misc
    Replies:
    5
    Views:
    230
    Anno Siegel
    Oct 13, 2003
  4. Zapanaz
    Replies:
    4
    Views:
    135
    Tad McClellan
    Oct 12, 2005
  5. Gert Brinkmann

    How to send utf-8 data using LWP::UserAgent?

    Gert Brinkmann, Jul 25, 2006, in forum: Perl Misc
    Replies:
    8
    Views:
    816
    Alan J. Flavell
    Jul 27, 2006
Loading...

Share This Page