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

By looking at the following from the documentation of the LWP::UserAgent module:
"$ua->post( $url, \%form, $field_name => $value, ... )"
it seems to me that I can pass BOTH a hashref AND a list of name value pairs to the SAME form. Is that correct?

I am currently trying something like this:

$response = $browser->post( 'http://site.com/form.php', \%form, 'val1' => 1, 'val2' => 0, @header);

This, however, doesn't seem to work. Any ideas?


use strict; use CGI;

Replies are listed 'Best First'.
Re: LWP post method, mutliple parameters
by merlyn (Sage) on Dec 22, 2007 at 21:52 UTC
    Those are for headers, not form params. They'll show up as "val1: 1" in the post header, which you would see if you checked $ENV{HTTP_VAL1} in the form processor, for example.
      So I'd have to throw all those into the hashref before sending it off via post()? Any better way to do this? I have a subroutine that strips form parameters from source html and returns them as a hash. I want to add more set parameters to that hash and then send them off as a post.

      use strict; use CGI;
        What was in place before was
        $ua->post( $url, [ name => value, name => value ], @header)
        Would it be the same to replace the [ name => value...] with a hashref?

        use strict; use CGI;