Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: LWP::UserAgent Trying to automate session authentication

by spazm (Monk)
on Jun 01, 2012 at 23:06 UTC ( #973879=note: print w/ replies, xml ) Need Help??

in reply to LWP::UserAgent Trying to automate session authentication

1) You built a POST request, but didn't actually send it.
2) I'd suggest using WWW::Mechanize instead of hand rolled UA calls, let it handle the nitty-gritty.

#!/usr/bin/env perl use strict; use HTTP::Cookies; use WWW::Mechanize; use Data::Dumper; my ($username, $password); while (!$username || !$password) { ### Prompt for username print "\nAkamai Administrator credentials\n"; print "username> "; $username = <STDIN>; ### Prompt for password print "password> "; system 'stty -echo'; $password = <STDIN>; system 'stty echo'; chomp($username, $password); } my $login_url = ''; my $real_page = ''; my $mech = WWW::Mechanize->new(); $mech->agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Ge +cko/20100101 Firefox/12.0"); $mech->get( $real_page ); if ( $mech->base =~ m/$login_url/) { $mech->submit_form( form_number => 2, fields => { "User ID" => $username, "Password" => $password } ); } print $mech->content();
This gets me as far as verifying that I don't have a login:
"Information entered does not match what we have on file. Please try again."
The main points here are
  1. request the page you want
  2. detect if you are on the login page and submit the login credentials

Comment on Re: LWP::UserAgent Trying to automate session authentication
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://973879]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2014-07-10 12:49 GMT
Find Nodes?
    Voting Booth?

    When choosing user names for websites, I prefer to use:

    Results (209 votes), past polls