How do I use Perl's LWP to log in to a web application?
Posted
by maxjackie
on Stack Overflow
See other posts from Stack Overflow
or by maxjackie
Published on 2009-06-22T19:16:51Z
Indexed on
2010/06/15
6:32 UTC
Read the original article
Hit count: 265
I would like to write a script to login to a web application and then move to other parts of the application:
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use Data::Dumper;
$ua = LWP::UserAgent->new(keep_alive=>1);
my $req = POST "http://example.com:5002/index.php",
[ user_name => 'username',
user_password => "password",
module => 'Users',
action => 'Authenticate',
return_module => 'Users',
return_action => 'Login',
];
my $res = $ua->request($req);
print Dumper(\$res);
if ( $res->is_success ) {
print $res->as_string;
}
When I try this code I am not able to login to the application. The HTTP status code returned is 302 that is found, but with no data.
If I post username/password with all required things then it should return the home page of the application and keep the connection live to move other parts of the application.
© Stack Overflow or respective owner