[Ilugc] access password protected sites using perl

  • From: ilugid@xxxxxxxxx (Ashish Verma)
  • Date: Thu Jan 21 05:28:48 2010

Hi,

How can we access a password protected site using perl. Not the ones' that
use a realm (wherein there is a popup window for username and password) type
of authentication. By password protected I mean sites like gmail, yahoo etc,
wherein the password needs to be supplied to the ID of field. I have tried
using the LWP module POST method, however, GMAIL does not accept post
method.

Regards,
Ashish


PS: Actually now I am unable to even access pages that use a realm for
authentication, I was going through a very informative page in CPAN
documentation, however am unable to find it. Further, I am not even able to
rewrite the code to access those type of pages.


#!/usr/bin/perl -w
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use HTTP::Request::Common qw(GET);
use HTTP::Cookies;
use LWP::Simple;
use Net::SSLeay;

my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET
CLR 2.0.50727; .NET CLR 3.0.04506; InfoPath.2; MS-RTC LM 8)');
$ua->no_proxy('172.25.203.131','server.av.net');
$ua->proxy(http => 'http://myproxy.net');
$ua->cookie_jar(  HTTP::Cookies->new( file => 'mycookies.txt', autosave => 1
)  );
######### $ua->credentials('172.25.203.131/isos/', 'This_is_a_realm',
'ashish', 'password')  ##### What does this (credentials) do. Isn't
mentioning this supposed to make the scenario 2 below work?

1. my $req = GET 'http://172.25.203.131/isos/';                  # This
works
2. my $req = GET 'http://172.25.203.131/isos/';                  # This
doesn't works if "isos" is password protected.
3. my $req = POST 'http://172.25.203.131/isos/'  [username => 'ashish',
password => 'password'] ;                 # This doesn't works  The
"informative page" I have mentioned above had an explanation as to how to
make the above POST request to work with some reasons. I can't find that
now.

my $res = $ua->request($req, 'test.html');

exit 0;

Please help!!!

Other related posts: