http://qs321.pair.com?node_id=417925

destined2doom has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am unable to connect to any URL using LWP. I am behind a proxy! I've read usual trouble shoot tips but was unable to make things work.Follwoing is the code:
#!/usr/bin/perl -w # Uses use strict; use LWP 5.64; # URL my $url = 'http://google.com'; # User Agent Object my $browser = LWP::UserAgent->new; # $browser->proxy([qw(http ftp)], 'http://google.com:80'); $browser->env_proxy; my $response = $browser->get( $url); die "Couldn't get $url -- " ,$response->status_line unless $response->is_success;
even if I comment out env_proxy and uncheck comment from
$browser->proxy([qw(http ftp)], 'http://google.com:80'
.It is not working. Following are my proxy settings:
Address:Dialup Port:80
I am looking forward to your help :) Shudh

Replies are listed 'Best First'.
Re: Cannot connect using LWP :behind Proxy
by William G. Davis (Friar) on Dec 29, 2004 at 06:49 UTC

    Hi. First, you should really wrap all of your code in <code></code> tags when you post it here so it displays correctly. Here's your code reposted using <code> tags:

    #!/usr/bin/perl -w # Uses use strict; use LWP 5.64; # URL my $url = 'http://google.com'; # User Agent Object my $browser = LWP::UserAgent->new; # $browser->proxy(>qw(http ftp), 'http://google.com:80'); $browser->env_proxy; my $response = $browser->get( $url); die "Couldn't get $url -- " ,$response->status_line unless $response->is_success;

    Next, have you tried it with both the call to proxy() and env_proxy() commented out? If so, then see this, and then try to figure out what proxy settings your web browser is using (Edit->Preferences->Advanced->Proxies in Mozilla). Obviously, if you can post here using it, then the browser somehow managed to connect to the outside world. Get the host and port number of the proxy used for HTTP (and FTP too, if you want it) and then tell LWP::UserAgent to use that proxy using the proxy() method:

    $browser->proxy(http => 'http://proxy.whateverisp.com:8001'); $browser->proxy(ftp => 'http://proxy.whateverisp.com:2101');
      Hi William, Thank you for the response. I would take care to put da code under  and from future posts.The problem is solved after I set HTTP_Proxy as my environment variable and the same code works now . I would again like to thank you for the quick reply post Regards Shudh
Re: Cannot connect using LWP :behind Proxy
by matija (Priest) on Dec 29, 2004 at 07:45 UTC
    First, use either $browser->proxy or $browser->env_proxy, but not both.

    Second, in your $browser->proxy you set the proxy to http://google.com:80/ that is extremely unlikely to work - google, after all, does not offer proxy services. You need to put the actual proxy contact information in there. The easiest way to find it is to see what your browser is using...