And ran your code and a debug and look at the response means that it got the data just fine:#!/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;
I get:#!/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; }
Which responds correctly because I issue a bad password (1999 instead of 1234). Is your page being protected by something in .htaccess?# 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&j_password=1999</title> </head><body><h1>Bummer, wrong password!</h1></body></html> DB<8>
Celebrate Intellectual Diversity
In reply to Re: WWW::Mechanize Problem
by InfiniteSilence
in thread WWW::Mechanize Problem
by pilgrim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |