I don't know pilgrim, but I tried your code and I don't see anything wrong with any of it. I created a bogus page:
#!/usr/bin/perl -w use strict; use CGI qw/:standard/; CGI::initialize_globals(); print header; print start_html($ENV{'QUERY_STRING'}); if (!defined(param('j_username'))) { print start_form(-name=>'a_form', -method=>'GET', -action=>'login.cg +i'); print textfield(-name=>'j_username'); print br,password_field(-name=>'j_password'); print br,submit(); print end_form; } else { if ((defined(param('j_password'))) and (param('j_password') eq '1234' +)) { print h1('YEAH!'); } else { print h1('Bummer, wrong password!'); } } print end_html; 1;
And ran your code and a debug and look at the response means that it got the data just fine:
#!/usr/local/bin/perl -w use strict; use warnings; use WWW::Mechanize; my $url = 'http://localhost/cgi-bin/login.cgi'; my $ua = WWW::Mechanize->new(); my $user = 'foobie'; my $clearpass = '1999'; $ua->get($url); #$ua->form_number('1'); #$ua->field('j_username',$user); #$ua->field('j_password',$clearpass); #$ua->submit(); $ua->set_fields("j_username" => $user, "j_password" => $clearpass); $ua->submit(); if ($ua->success()) { print "Yay!"; } else { print "Login failed: " . $ua->response->status_line; }
I get:
# from perl -d node_298151.pl DB<7> p $ua->res->{'_content'} <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>j +_username= foobie&amp;j_password=1999</title> </head><body><h1>Bummer, wrong password!</h1></body></html> DB<8>
Which responds correctly because I issue a bad password (1999 instead of 1234). Is your page being protected by something in .htaccess?

Celebrate Intellectual Diversity


In reply to Re: WWW::Mechanize Problem by InfiniteSilence
in thread WWW::Mechanize Problem by pilgrim

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.