Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Welcome to the Monastery
 
PerlMonks  

LWP proxy user authentication

by imrags (Monk)
on May 26, 2011 at 10:49 UTC ( #906804=perlquestion: print w/ replies, xml ) Need Help??
imrags has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks

I'm trying to write a simple code which will get details of the website using LWP.
We've a proxy server and it needs user credentials (AD)...
I've written the code below but the script just hangs:
use LWP::Simple; use LWP::UserAgent; my $user = 'user'; my $pwd = 'password'; my $browser = LWP::UserAgent->new(); $browser->credentials('http://proxy.srvr.com:8080/','domain',$user=>$p +wd); my $url = 'http://www.google.com'; my $response = $browser->get($url); print $response->header("Server"),"\n";
I also tried using basic_authorization, http::headers etc.
I am pretty sure it's the problem with proxy... Any help?
Raghu

Comment on LWP proxy user authentication
Download Code
Re: LWP proxy user authentication
by Anonymous Monk on May 26, 2011 at 11:07 UTC
    turn on debugging/tracing or whip out the wireshark
Re: LWP proxy user authentication
by Khen1950fx (Canon) on May 27, 2011 at 07:39 UTC
    I noticed that you used LWP::Simple. You can take that out. I also noticed that you used $pwd for password---that's confusing because pwd stands for "present working directory", so change that to $pass.

    The main problem that I see with your code is that you need to explicitly say that you're behind a proxy. What I would do is set the environmental variable for http_proxy. Here you could do:

    export http_proxy=http://proxy.srvr.com:8080/
    Then run your script:
    #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $url = 'http://www.google.com'; my $user = 'user'; my $pass = 'pass'; my $domain = 'domain'; my $ua = LWP::UserAgent->new(); $ua->env_proxy; $ua->credentials('proxy.srvr.com:8080', $domain, $user, $pass); my $res = $ua->get($url); print $res->header("Server"), "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://906804]
Approved by SilasTheMonk
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: (18)
As of 2014-04-18 15:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (469 votes), past polls