Passing Post Params & Object Reference ?

Discussion in 'Perl Misc' started by still me, Oct 14, 2007.

  1. still me

    still me Guest

    I am using LWP to do a POST. I need some help automating the passing
    of parameters and getting the object reference to work.

    Here's the (hard coded) version that works fine;
    my $response = $browser->post( $url,['test1'=>'001', 'test2' => 'it
    works']););

    What I'd like to do is to set up an array (or hash) with the parameter
    names and values so that I can change the parameters to be passed as
    simply by altering the hash names/values. Then I'd just generate the
    passed parameter string for as many values as are in the array.

    Here's a hardcoded sample (no array for simplicity) that I tried as a
    test just to figure out how to get the parameters passed:

    my $param1 = "'test1'=>'001',";
    my $param2 = "'test2'=>'002'";
    my $response = $browser->post( $url,[$param1, $param2]);

    But, it didn't pass the parameters. I assume that's because I
    destroyed the object reference by doing what I did, but I don't
    understand Perl objects and variable translation enough to know how to
    construct a working object reference.

    Thanks for any help,
    still me, Oct 14, 2007
    #1
    1. Advertising

  2. still me wrote:
    > I am using LWP to do a POST. I need some help automating the passing
    > of parameters and getting the object reference to work.
    >
    > Here's the (hard coded) version that works fine;
    > my $response = $browser->post( $url,['test1'=>'001', 'test2' => 'it
    > works']););
    >
    > What I'd like to do is to set up an array (or hash) with the parameter
    > names and values so that I can change the parameters to be passed as
    > simply by altering the hash names/values. Then I'd just generate the
    > passed parameter string for as many values as are in the array.
    >
    > Here's a hardcoded sample (no array for simplicity) that I tried as a
    > test just to figure out how to get the parameters passed:
    >
    > my $param1 = "'test1'=>'001',";
    > my $param2 = "'test2'=>'002'";
    > my $response = $browser->post( $url,[$param1, $param2]);


    Try this:

    my %params = ( test1 => '001', test2 => '002' );
    my $response = $browser->post( $url, [ %params ] );

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Oct 14, 2007
    #2
    1. Advertising

  3. still me

    still me Guest

    On Sun, 14 Oct 2007 05:52:49 +0200, Gunnar Hjalmarsson
    <> wrote:

    >> Here's a hardcoded sample (no array for simplicity) that I tried as a
    >> test just to figure out how to get the parameters passed:
    >>
    >> my $param1 = "'test1'=>'001',";
    >> my $param2 = "'test2'=>'002'";
    >> my $response = $browser->post( $url,[$param1, $param2]);

    >
    >Try this:
    >
    > my %params = ( test1 => '001', test2 => '002' );
    > my $response = $browser->post( $url, [ %params ] );


    Thanks, that got me going in the right direction.
    still me, Oct 15, 2007
    #3
    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. bogdan
    Replies:
    0
    Views:
    390
    bogdan
    Apr 10, 2008
  2. Barry
    Replies:
    9
    Views:
    431
    Ara.T.Howard
    Sep 15, 2005
  3. Belorion
    Replies:
    1
    Views:
    160
    James Britt
    Feb 9, 2006
  4. Replies:
    7
    Views:
    152
    Michael Granger
    Feb 15, 2008
  5. Sending params through POST

    , Sep 21, 2006, in forum: Javascript
    Replies:
    1
    Views:
    73
    Benjamin
    Sep 21, 2006
Loading...

Share This Page