Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

LWP::UserAgent proxy

by whittick (Novice)
on Feb 27, 2014 at 14:37 UTC ( #1076402=perlquestion: print w/ replies, xml ) Need Help??
whittick has asked for the wisdom of the Perl Monks concerning the following question:

I stumbled accross a previous question from 2004 but didn't really want to resurrect it: http://www.perlmonks.org/?node_id=411687

I'm interested in the following code mentioned and I'm struggling to understand the two user/username and pass/password variables:

my $ua = LWP::Custom->new(); $ua->proxy(["http"], "http://proxy.com"); $ua->set_basic_credentials( $user, $pass ); package LWP::Custom; use base 'LWP::UserAgent'; # add a set_basic_credentials method, using a closure to remember { my ( $username, $password ); sub set_basic_credentials{ ( $username, $password ) = @_[1..2] } sub get_basic_credentials{ $username, $password }; }

I Assume user and pass refer to the proxy credentials, what does username and password refer to?

Also if my proxy were a hostname rather than a web address would I just insert http:// before the hostname, or use the IP address, or just the hostname? I'm getting a bit confused!

Thanks.

Comment on LWP::UserAgent proxy
Download Code
Re: LWP::UserAgent proxy
by SimonPratt (Beadle) on Feb 27, 2014 at 16:23 UTC

    As per the docs:

    $ua->get_basic_credentials( $realm, $uri, $isproxy ) This is called by request() to retrieve credentials for documents protected by Basic or Digest Authentication. The arguments passed in is the $realm provided by the server, the $uri requested and a boolean flag to indicate if this is authentication against a proxy server.

    The method should return a username and password. It should return an empty list to abort the authentication resolution attempt. Subclasses can override this method to prompt the user for the information. An example of this can be found in lwp-request program distributed with this library.

    The base implementation simply checks a set of pre-stored member variables, set up with the credentials() method.

    To answer your question, $username is $user and $password is $pass. Extending the class simply allows the caller to store login credentials for the object

Re: LWP::UserAgent proxy
by thomas895 (Hermit) on Feb 28, 2014 at 07:31 UTC

    I Assume user and pass refer to the proxy credentials, what does username and password refer to?
    These refer to the basic authentication(as per RFC2617), not the proxy authentication. I assume that you prepend the auth credentials to the proxy URI as demonstrated in RFC2396 §3.2.2, though it is said to be "not recommended".

    if my proxy were a hostname rather than a web address would I just insert http:// before the hostname, or use the IP address, or just the hostname?
    Hostnames should be resolved to their corresponding addresses; see your network administrator and/or consult your operating system manuals to find out how to set this up. The docs do always make an indication of an initial http://
    It sounds like you already have it set up, though, so http://proxy-hostname:port ought to be sufficient. Note that this does not work for anything besides HTTP proxies; SOCKS will not work.

    ~Thomas~ 
    "Excuse me for butting in, but I'm interrupt-driven..."

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1076402]
Approved by ww
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-09-21 22:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls