dneedles has asked for the wisdom of the Perl Monks concerning the following question:
Second program#!/usr/bin/perl use WWW::Mechanize; ## Automate Grabbing Webpages use strict; my $url = "http://10.10.10.10/bat.html"; my $mech = WWW::Mechanize->new(autocheck => 1); $mech->default_headers->authorization_basic("user", "pass"); $mech->get($url); my $page = $mech->content; ## INITIAL OUTPUT print "INITIAL REQUEST\n"; $mech->dump_all(undef, 1); print $page; print "\n\n\n"; my $resp2; ## STATE: TEST (CANNOT START OR CHECK, BUT CAN STOP) if ($page=~/reset.*?disabled.*?Reset/) { print "TEST STOP\n"; $resp2=$mech->submit_form( form_number => 1, fields =>{ a => 2, b => '3,2,2', }, ); ## STATE: NO TEST (CAN START, CHECK, BUT NOT STOP) } else { print "TEST START\n"; $resp2=$mech->submit_form( form_number => 1, fields => { c => 49.0, d => 0.3, e => 45.0 , a => 1, b => '3,2,2', }, ); } ## AFTER FORM FILL OUT $mech->dump_all(undef, 1); print $resp2->content; print "\n\n\n";
I also tried the second program with a number of variations:#!/usr/bin/perl use HTTP::Request::Common qw(POST); use LWP::UserAgent; use strict; my $ua = LWP::UserAgent->new(); #$ua->credentials( # '10.10.10.10:80', # 'PSC500', # 'user' => 'pass' #); # log in to authentication page. my $req = HTTP::Request->new(GET => 'http://10.10.10.10/bat.html'); $req->authorization_basic('user', 'pass'); ## INITIAL OUTPUT print "INITIAL REQUEST\n"; my $resp = $ua->request($req); my $content = $resp->as_string; print $content; print "\n\n\n"; my $req2; ## STATE: TEST (CANNOT START OR CHECK, BUT CAN STOP) if ($content=~/reset.*?disabled.*?Reset/) { print "TEST STOP\n"; $req2= POST 'http://10.10.10.10/bat.html', [ a => 2, b => '3,2,2', ]; ## STATE: NO TEST (CAN START, CHECK, BUT NOT STOP) } else { print "TEST START\n"; $req2= POST 'http://10.10.10.10/bat.html', [ c => 49.0, d => 0.3, e => 45.0 , a => 1, b => '3,2,2', ]; } $req2->authorization_basic('user', 'pass'); my $resp2 = $ua->request($req2); my $content = $resp->as_string; print $content; print "\n\n\n";
I got the same result where the page was read but the form values did not post. Any ideas?$req2= HTTP::Request->new(POST => 'http://10.10.10.10... Used ua->credentials(... etc.
|
|---|