in reply to LWP::UserAgent vs WWW::Mechanize

when $agent is of LWP::Agent i am logged in, but with WWW::Mechanize I am redirected to the login screen.
Do you mean LWP::UserAgent?

It just so happens that WWW:Mechanize is a sub-class of LWP::UserAgent. So if you can't figure out what's going wrong, an option is to use LWP::UserAgent methods to log in and WWW::Mechanize methods for everything else.

Replies are listed 'Best First'.
Re^2: LWP::UserAgent vs WWW::Mechanize
by jcdento (Novice) on Jun 13, 2008 at 16:00 UTC
    yes, sorry i meant LWP::UserAgent. The thing is, i am using identical methods in both scripts, and lwp is working, and mech isnt. My objects are:
    y $agent = LWP::UserAgent->new(cookie_jar => HTTP::Cookies->new, reque +sts_redirectable => [ 'GET', 'HEAD', 'POST' ]); $agent->agent( 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8 +.1.14) Gecko/20080404 Firefox/2.0.0.14'); $agent->default_header('Accept' => "text/xml,application/xml,applicati +on/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", 'Accept-Language' => "en-us,en;q=0.5", 'Accept-Charset' => "ISO-8859-1,utf-8;q=0.7,*;q=0.7", 'Keep-Alive' => "300", 'Connection' => "keep-alive");
    and
    my $agent = WWW::Mechanize->new(autocheck=>1, agent=> 'Mozilla/5.0 (Wi +ndows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/ +2.0.0.14'); $agent->max_redirect(100); $agent->default_header('Accept' => "text/xml,application/xml,applicati +on/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5", 'Accept-Language' => "en-us,en;q=0.5", 'Accept-Charset' => "ISO-8859-1,utf-8;q=0.7,*;q=0.7", 'Accept-Encoding' => "gzip,deflate", 'Keep-Alive' => "300", 'Connection' => "keep-alive", 'TE' => "");
      WWW::Mechanize's version of ->request modifies the request before issuing it, and that could be the problem. Try this:
      $agent = WWW::Mechanize->new(...); ...set up $agent... $agent->LWP::UserAgent::request($form->click);