fwi, this is a simplified version that works ok.

Form (monk.html)

<html> <head> <title>test mech</title> </head> <body> <form action="/cgi/process.cgi" METHOD="get" name="enterLogin" > <input type="text" size="8" name="id"> <input type="password" size="8" name="pwd"> <input type="image" src="pic/pic01.jpg" border="+0"> </form> </body> </html>
The script called by the form (process.cgi)

#!c:\Perl\bin\perl.exe use warnings; use strict; use CGI::Simple; use CGI::Carp (qw(fatalsToBrowser)); my $q = CGI::Simple->new(); print $q->header; my $pwd = $q->param('pwd'); my $id = $q->param('id'); print " <html> <head> <title>test mech</title> </head> <body> <p>hi there</p> <p>id: $id</p> <p>pwd: $pwd</p> </body> </html> ";
And the Mech script

#c:/Perl/bin use warnings; use strict; use WWW::Mechanize; my $m = WWW::Mechanize->new( autocheck=>1 ); my $agent = LWP::UserAgent->new; $agent->cookie_jar(HTTP::Cookies->new); $m->get("http://localhost/monk.html"); my $r = $m->submit_form( fields => { id => "XXXXXXX", pwd => "YYYYYYY", } ); print $m->content;
Output:

---------- Capture Output ---------- > "c:\perl\bin\perl.exe" m.cgi <html> <head> <title>test mech</title> </head> <body> <p>hi there</p> <p>id: XXXXXXX</p> <p>pwd: YYYYYYY</p> </body> </html> > Terminated with exit code 0.
Having the image field instead of a submit button didn't seem to hurt.

Hope that helps.


In reply to Re: Script using WWW::Mechanize fails to log in by wfsp
in thread Script using WWW::Mechanize fails to log in by Anonymous Monk

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.