So it drives me crazy. Basically, when I hard-code my user name and password, I can log in without problems. But I want to invite the user to enter a username and password, since I would like to share this program with others. (the program should go to our courses website and upload all our course information - lectures, hw, etc.)
This code works:
use WWW::Mechanize;
use LWP;
my $username = 'user';
my $password = 'pass';
my $mech = WWW::Mechanize->new();
$mech -> cookie_jar(HTTP::Cookies->new());
$mech -> get('log-in url');
$mech -> form_name('theform');
$mech -> field ('username' => $username);
$mech -> field ('password' => $password);
$mech -> click ('log in');
print $mech-> content();
however, when I try and prompt the user to enter login information, it now works. printing the content returns the html of the login page, and not the next page (course page for the specified user).
use LWP;
use WWW::Mechanize;
my $login_url = 'log-in url';
print "\nUser name: ";
my $username = <>;
print "Password: ";
my $password = <>;
my $mech = WWW::Mechanize->new();
$mech -> cookie_jar(HTTP::Cookies->new());
$mech -> get($login_url);
$mech -> form_name('theform');
$mech -> field ('username' => $username);
$mech -> field ('password' => $password);
$mech -> click ('log in');
print $mech-> content();
, . / ..... ( , - , )