Thursday, March 01, 2007

Some Basic Perl Help

This is for anyone attempting to script a perl program that can login to a website. I had to use something called 'AUTHORIZATION: BASIC '. This doesn't sound complicated, and it isn't, but it took me a fair time to find the proper method.

If you are logging into an https site, you'll need the Crypt::SSLeay module. This can be acquired via CPAN for the source or via the University of Winnipeg's ppd download site for the ActiveState package. You'll, also need LWP, which comes standard with ActiveState Perl.

Once you've got your functional Perl installation, you just need to be able to create the proper header to POST with. Here, I was stumped, and googled 'perl', 'authorization', and 'basic' all the live long day without finding an example. Finally, I trolled through the lwp cookbook in the ActiveState documentation, and I found this:

use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET => '
http://www.linpro.no/secret/');
$req->authorization_basic('aas', 'mypassword');
print $ua->request($req)->as_string;


This was all I needed.

Labels: ,