in reply to Re: File upload with LWP::UserAgent
in thread File upload with LWP::UserAgent

Thanks for suggesting WWW::Mechanize. I'm getting a little further, but I think my problem now is that I can't get cookies working. When I authenticate, the appropriate page is returned, but the next page I request prompts me to log in again. Here's my code:
use HTTP::Cookies; use WWW::Mechanize; my $cj = HTTP::Cookies->new( autosave => 1, ignore_discard => 1 ); my $mech = WWW::Mechanize->new( cookie_jar => $cj ); $mech->get( 'http://example.com/login.action' ); if ($mech->success()) { $mech->submit_form( form_name => 'loginform', fields => { os_usern +ame => 'username', os_password => 'password' } ); } if ($mech->success()) { $mech->follow_link( text => 'Training'); # This is where I get red +irected to the login page again! }

Am I using cookies improperly, or is there some other problem with my code?

Replies are listed 'Best First'.
Re^3: File upload with LWP::UserAgent
by PerlRob (Sexton) on Jun 13, 2008 at 03:30 UTC
    I figured it out. The login form has a checkbox for remembering your username/password (as login forms often do). I simply had to use the tick() method to make sure that box was checked so that I could receive the login cookie and access subsequent pages.

    Thanks again for suggesting WWW::Mechanize!