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

hi everyone. im not sure how to explain my situation because im not a native english speaker so please bear with my grammar. awhile ago my boss asked me to make a perl script to simulate a user signup on a beta website for testing purposes. i came from a hardware background with zero knowledge of perl so im really in high emotions when he asked me to do such. anyway, i started reading perl noobs howtos up to mid-advanced , then perldocs until i came up with a crippled code. what im trying to do is this: automate a single signup process on a remote https website, grab whatever messages returned, and store the output on a file or stdout. the website i am being asked to make a perl script is http://www.i.ph/signup.php
#!/usr/bin/perl -w use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->agent("Mozilla 8.0"); use HTTP::Request::Common qw(POST); my $req = (POST 'https://www.i.ph/signup.php', [ "username" => "nonsense", "usermail" => 'myemail@yahoo.com', "userpassword1" => "password", "userpassword2" => "password", "usermobile" => "639165263265", "userchallenge" => "test test", "useranswer" => "test", "agreement" => 1 ]); $request = $ua->request($req); $content = $request->content; print $content; exit;
"agreement" here is a checkbox. i tried google-izing this, searched through perdocs and cpan but either i found nothing relevant or i just didnt know where to look. obviously what i did on the code above is wrong. surely there is another (way better) way to do this, im not even sure this code nearly accomplishes what im trying to do. atleast i hope i have stated my objective/goal clearly. please enlighten me. note:i believe i have all the necessary modules installed (SSLcrypt, SSLeay, etc.) since i can GET the https page.

Replies are listed 'Best First'.
Re: https POST and checkboxes
by Corion (Patriarch) on Sep 20, 2005 at 15:38 UTC

    The easiest way of automating web access is to use WWW::Mechanize, which encapsulates LWP::UserAgent and provides among others the tick method, which selects a checkbox on a form.

    You might also want to take a look at the FireFox webbrowser and the Live HTTP Headers, which will show you exactly what gets sent by the browser.

    There are also two recorder tools to record and later playback a session, namely HTTP::Recorder, which turns your browser session into a WWW::Mechanize script, and WWW::Mechanize::Shell (by me), which gives you a command line interface to your browser, and turns that command session into a WWW::Mechanize script.

Re: https POST and checkboxes
by polettix (Vicar) on Sep 20, 2005 at 20:16 UTC
    Corion pointed out all wisdom on the subject. Just for the next time (or if you still don't succeed), please post what error you get exactly, or the exact reason why you think that the code above is wrong. You surely agree that it's quite blurred a hint if you want a sharp answer :)

    Flavio
    perl -ple'$_=reverse' <<<ti.xittelop@oivalf

    Don't fool yourself.
Re: https POST and checkboxes
by marcpascual (Acolyte) on Sep 21, 2005 at 01:06 UTC
    yes, exactly. for the last 2 hours i am awake i started reading information about the modules he pointed out. i will try and work it out myself first and will ask you guys again incase i cant come up with anything. thank you so much!
Re: https POST and checkboxes
by marcpascual (Acolyte) on Sep 21, 2005 at 02:43 UTC
    i got it working now with the aid of livehttpheader. thank you corion and frodo.
    #!/usr/bin/perl -w use LWP::UserAgent; $ua = LWP::UserAgent->new; $ua->agent("Mozilla 8.0"); use HTTP::Request::Common qw(POST); my $req = (POST 'https://www.i.ph/signup_check.php', [ username => 'recall', useremail => 'acerel54@linuxmail.org', userpassword1 => 'recall', userpassword2 => 'recall', usermobile => 639165263265, userchallenge => 'recall', useranswer => 'recall', agreement => 'on', domainname => "", 'submit.x' => 49, 'submit.y' => 12 ]); $request = $ua->request($req); $content = $request->content; print $content; exit;
    i just need to format the printed html content into something more human-readable and for further processing with Test::More. any tips?