Link to home
Start Free TrialLog in
Avatar of planetiowa
planetiowa

asked on

Accessing password protected web URLs from a Perl script.

I'm a beginner at this but I have created simple Perl scripts to read from a web page using LWP::Simple  and LWP:UserAgent, however, I would now like to read a web page that I normally have to enter a username and password to get to.  How do I do this from a Perl script?

Thanks!
Avatar of ozo
ozo
Flag of United States of America image

where is the username and password entered?
for some kinds of passwords you might do
perl -MLWP::Simple -e 'getprint "http://username:password@host/path"'
Avatar of Perl_Diver
Perl_Diver

http://search.cpan.org/~gaas/libwww-perl-5.805/lwpcook.pod#ACCESS_TO_PROTECTED_DOCUMENTS


ACCESS TO PROTECTED DOCUMENTS

Documents protected by basic authorization can easily be accessed like 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;
Avatar of planetiowa

ASKER

I tried the first suggestion but I got errors about an unrecognized host.  On the second response using the LWP::UserAgent method, this just returns an htm page with the username and password boxes again.  This is the base page I am trying to access:
http://cp.cr-cath.pvt.k12.ia.us/
ASKER CERTIFIED SOLUTION
Avatar of Perl_Diver
Perl_Diver

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thnaks for the information.  I'll have to study that for awhile but it looks promising.