#!/usr/bin/perl --
use strict;
use warnings;
use WWW::Mechanize 1.66;
use URI::file;
my $ua = WWW::Mechanize->new( autocheck => 1, );
$ua->add_handler(
"request_send",
sub { $_[0]->dump; return; },
m_method => 'POST'
);
$ua->timeout(1);
#~ $ua->get( URI::file->new( 'test.html' )->abs(URI::file->cwd) );
$ua->get( URI::file->new(__FILE__)->abs( URI::file->cwd ) );
$ua->update_html( <<'HTML', '.' );
test.html : localhost form
HTML
print '# ', __LINE__, ' ', '#' x 33, "\n";
eval {
$ua->submit_form(
form_number => 0,
fields => {qw' user_choice Enter '},
);
} or print "\n", __LINE__, " $@";
print '# ', __LINE__, ' ', '#' x 33, "\n";
eval {
$ua->back; # if autocheck => 0
$ua->form_number(0);
#~ $ua->set_fields( check => [ 3333, 5555 ] );# error, checkboxes not fields
$ua->tick( check => 2222 => 0 ); # untick/uncheck
$ua->tick( check => 3333 ); # tick/check
$ua->untick( check => 4444 ); # uncheck
$ua->tick( check => 5555 => 1 ); # check
$ua->click_button( value => 'Enter' ); # submit
} or print "\n", __LINE__, " $@";
print '# ', __LINE__, ' ', '#' x 33, "\n";
eval {
$ua->back; # if autocheck => 0
$ua->submit_form(
form_number => 0,
fields => {
qw' user_choice Enter ',
check => 1111,
check => 5555,
check => 6666,
},
);
} or print "\n", __LINE__, " $@";
print $ua->dump_forms,"\n\n";
__END__
$ perl mechanize.inline.submit_form3.pl
# 37 #################################
POST http://localhost/
Accept-Encoding: gzip
Referer: file:////~/temp/mechanize.inline.submit_form3.pl
User-Agent: WWW-Mechanize/1.66
Content-Length: 37
Content-Type: application/x-www-form-urlencoded
CategoryId25=on&check=2222&check=4444
43 Error POSTing http://localhost/: Can't connect to localhost:80 (timeout) at mechanize.inline.submit_form3.pl line 39
# 45 #################################
POST http://localhost/
Accept-Encoding: gzip
Referer: file:////~/temp/mechanize.inline.submit_form3.pl
User-Agent: WWW-Mechanize/1.66
Content-Length: 55
Content-Type: application/x-www-form-urlencoded
CategoryId25=on&check=3333&check=5555&user_choice=Enter
56 Error POSTing http://localhost/: Can't connect to localhost:80 (timeout) at mechanize.inline.submit_form3.pl line 55
# 58 #################################
POST http://localhost/
Accept-Encoding: gzip
Referer: file:////~/temp/mechanize.inline.submit_form3.pl
User-Agent: WWW-Mechanize/1.66
Content-Length: 48
Content-Type: application/x-www-form-urlencoded
CategoryId25=on&check=6666&check=2222&check=4444
70 Error POSTing http://localhost/: Can't connect to localhost:80 (timeout) at mechanize.inline.submit_form3.pl line 61
POST http://localhost/
CategoryId25=on (checkbox) [/off|*on]
check=6666 (checkbox) [:/off|1111]
check=2222 (checkbox) [/off|*2222]
check= (checkbox) [*/off|3333]
check=4444 (checkbox) [/off|*4444]
check= (checkbox) [*/off|5555]
user_choice=Enter (submit)
user_choice=Leave (submit)