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

I can't figure out how to set the values of a multiple select list for the POST method of LWP::UserAgent. I've read perldoc lwpcook, CPAN, Spidering Hacks, Perl & LWP; and still can't figure it out!!!

My multiple select list looks like this:
<select multiple name=col size=24> <option selected value=KEYID>KEYID <option selected value=CPUTYPE>CPUTYPE <option selected value=INSTANCE_ID>INSTANCE_ID <option selected value=SYSTEM_ID>SYSTEM_ID </select>
And my LWP::UserAgent POST method looks like this:
my $response = $browser->post( $intrado, [ "group" => "Chicago", "table" => "CPCFG", ],@netscape_headers ); die "Error: ", $response->status_line unless $response->is_success;
How do I add the multiple select list to the POST? Would it be an array?
Or something like this:"col" => qw(KEYID CPUTYPE INSTANCE_ID SYSTEM_ID)

Replies are listed 'Best First'.
Re: POST Multiple Select List - LWP::UserAgent
by ikegami (Patriarch) on Sep 22, 2005 at 15:39 UTC

    IIRC, it's
    "col" => [ qw( KEYID CPUTYPE INSTANCE_ID SYSTEM_ID ) ]

    What you had is the same as
    "col", "KEYID", "CPUTYPE", "INSTANCE_ID", "SYSTEM_ID"
    which is the same as
    "col" => "KEYID", "CPUTYPE" => "INSTANCE_ID", "SYSTEM_ID"
    which is obviously wrong.

    Update: Confirmed.

    LWP::UserAgent says:

    This method will use the POST() function from HTTP::Request::Common to build the request. See HTTP::Request::Common for a details on how to pass form content and other advanced features.

    HTTP::Request::Common says:

    Multivalued form fields can be specified by either repeating the field name or by passing the value as an array reference.

    so either of the following should work:

    col => [ qw( KEYID CPUTYPE INSTANCE_ID SYSTEM_ID ) ]
    col => 'KEYID', col => 'CPUTYPE', col => 'INSTANCE_ID', col => 'SYSTEM_ID'
Re: POST Multiple Select List - LWP::UserAgent
by svenXY (Deacon) on Sep 22, 2005 at 15:41 UTC
    Hi,
    you seem to try to select a couple of list entries and then probably klick a submit button. If that's the case, then WWW::Mechanize is probably much easier. It has WWW::Mechanize::Shell which is a webclient and allows you to save your history as a Perl script afterwards (i.e. you "build" your script by using the shell.
    Regards,
    svenXY
Re: POST Multiple Select List - LWP::UserAgent
by kwaping (Priest) on Sep 22, 2005 at 15:40 UTC