mhearse has asked for the wisdom of the Perl Monks concerning the following question:
I'm going nuts trying to automate this. Is there anything obviously wrong? Is there a better way to do this?
#!/usr/bin/env perl use strict; use HTTP::Cookies; use LWP::UserAgent; use HTTP::Request::Common qw(POST GET); 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 $ua = LWP::UserAgent->new( cookie_jar => HTTP::Cookies->new(), requests_redirectable => [ ], timeout => 10, agent => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:12.0) Ge +cko/20100101 Firefox/12.0" ); my $target; my $req = GET 'https://control.akamai.com/EdgeAuth/login.jsp'; if ($ua->request($req)->as_string =~ /"TARGET_URL" value="(.*)" \/>\n/ +) { $target = $1; } else { print "Can't proceed without: TARGET_URL\n"; exit; } $req = POST 'https://control.akamai.com/EdgeAuth/userLogin', [ login => "Log In", TARGET_URL => $target, username => $username, password => $password ]; $req = GET 'https://control.akamai.com/home/view/main'; print $ua->request($req)->as_string;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: LWP::UserAgent Trying to automate session authentication
by spazm (Monk) on Jun 01, 2012 at 23:06 UTC | |
Re: LWP::UserAgent Trying to automate session authentication
by Khen1950fx (Canon) on Jun 02, 2012 at 10:04 UTC |
Back to
Seekers of Perl Wisdom