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

I am facing a problem when trying to GET a form with an option with an empty value. I.e. option1 has no value, option2 is 128 and option3 is 42.
$url = "http://host/index.php?option1=&option2=128&option3="; $option3 = 42; $response = $useragent->get( $url . $option3 );
This works fine but is not very readable. So I tried the following:
$url = "http://host/index.php"; $option3 = 42; $response = $useragent->get( $url, 'option1' => '', 'option2' => 128, 'option3' => $option3, );
This does not work. I tried '', undef and nothing as value of option1. None of this work. Can anyone tell me how to set an empty value for option1, please?

Replies are listed 'Best First'.
Re: How to set empty value for option in LWP-Get-Form
by Aristotle (Chancellor) on Feb 24, 2006 at 20:55 UTC

    Errm, passing additional parameters to get sets them as headers in the HTTP request, not as parameters in the URI. Use URI to do stuff like that.

    my $option3 = 42; my $uri = URI->new( 'http://host/index.php' ); $uri->query_form( option1 => '', option2 => 128, option3 => $option3, ); $response = $useragent->get( $uri );

    Makeshifts last the longest.

      Oh, this was a great mistake! LOL! Got confused by the syntax for POST forms, I think. With URI it works fine now. Thanks for enlightenment, monk. ;)