Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: How do I access a password protected site and access data?

by jaydon (Novice)
on Jun 28, 2005 at 17:49 UTC ( [id://470738]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I access a password protected site and access data?
in thread How do I access a password protected site and access data?

Obviously I'm doing something wrong... as that didn't work. Do I need to create an HTTP::Headers object first?

Replies are listed 'Best First'.
Re^3: How do I access a password protected site and access data?
by shiza (Hermit) on Jun 28, 2005 at 18:17 UTC
    Try dropping these use statements:
    use LWP::Simple; use HTTP::Request; use HTTP::Cookies;
    and add:
    use LWP;
    so your script will look something like this:
    #!/usr/bin/perl use strict; use LWP; use LWP::UserAgent; my $URI = 'https://www.domain.com/protected_realm'; my $user = 'foo'; my $pass = 'bar'; # define user agent my $ua = LWP::UserAgent->new(); $ua->agent("USER/AGENT/IDENTIFICATION"); # make request my $request = HTTP::Request->new(GET => $URI); # authenticate $request->authorization_basic($user, $pass); # except response my $response = $ua->request($request); # get content of response my $content = $response->content(); # do whatever you need to do with the content here print $content; exit;
    It would be wise to add error checking in there as well. :)

    Also, check out the docs for LWP here: LWP

    And the LWP::UserAgent docs for your cookie related needs: LWP::UserAgent

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-03-28 20:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found