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

Sup with this?
No worko...head banging against desk..

use HTTP::Request::Common; $URL='https://site.com/cgi-bin/script.cgi'; %form = ( key1=> 'value1, key2=> 'value2, ); $ua = LWP::UserAgent->new; $ua->timeout(10); $form_ref = { %form }; my $req = HTTP::Request->new(POST => $URL, $form_ref); my $res = $ua->request($req);
Not sure why I can't set the parameters in a hash rather than:
<code> key=>value, key2=>value, etc
because I have way to many dynamic keys and such...so why doesn't the $form_ref work? <code> I get this error:
Can't call method "clone" on unblessed reference at /usr/local/lib/perl5/site_perl/5.005/HTTP/Message.pm line 53.

Replies are listed 'Best First'.
Re: hash referencing with LWP
by chipmunk (Parson) on May 03, 2001 at 23:33 UTC
    I see three errors which have snuck into your code. Using HTTP::Request for POST requests can be a bit tricky.

    In the snippet POST => $URL, the fat comma makes POST a plain old string, rather than a call to the HTTP::Request::Common method named POST.

    The POST method takes the key/value pairs as an array ref, rather than a hash ref. That's just a convention that a lot of modules use.

    The POST method actually returns an HTTP::Request object itself.

    So, you want to do this instead: my $req = POST $URL, [ %form ]; Refer to the docs for HTTP::Request::Common and HTTP::Request for more examples.