Perl: the Markov chain saw | |
PerlMonks |
Re: LWP Authorization Problemby twerq (Deacon) |
on Jul 24, 2001 at 21:47 UTC ( [id://99427]=note: print w/replies, xml ) | Need Help?? |
(from comp.lang.perl.modules) As usual, there's more than one way to do it. 1. Use the credentials method of the LWP::UserAgent object:
Eg: Say your URL is http://www.somesite.com/page.html and when you try this with your browser, it pops up a box saying 'Enter username and password for XYZ'. $netloc in this example is 'www.somesite.com' and $realm in this case is 'XYZ'. 2. Call the authorization_basic method of your HTTP::Request object before passing it to the LWP::UserAgent's request method:
If you use method 1, the LWP::UserAgent will send one request which the server will reject with a 401 error. One of the headers in the 401 response will be the realm. The LWP::UserAgent will then look up it's internal table (populated by your calls to credentials) to find a matching netloc and realm. If this lookup returns a username and password, the LWP::UserAgent will resend the request with a basic authorization header. The second method allows you to set the username and password before making the initial request - assuming you supply the right credentials there will be no 401 error. There is no need to specify netloc and realm, as they are only used by the LWP::UserAgent's lookup routine. 'perldoc LWP::UserAgent' will tell you more about 1 'perldoc HTTP::Message' will tell you more about 2 (HTTP::Request is derived from HTTP::Message). --twerq
In Section
Seekers of Perl Wisdom
|
|