I am likely missing something very basic. The first program works fine. It reads the page, detects whether a test is started or not and either starts or stops the test. The second program correctly reads the pages and detects whether a test is started or not, but the form doesn't seem to work and the values do not get updated. Any ideas?

First 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";
Second program

#!/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 also tried the second program with a number of variations:
$req2= HTTP::Request->new(POST => 'http://10.10.10.10... Used ua->credentials(... etc.
I got the same result where the page was read but the form values did not post.

Any ideas?

In reply to A case where Mechanize works, LWP doesn't by dneedles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.