John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to make my Perl script access the web at work, through a firewall. I've read the LWP stuff carefully and tried many variations, doublechecked things, etc. Here is an example:

use strict; use warnings; require LWP::UserAgent; my $ua = LWP::UserAgent->new; $ENV{HTTP_proxy_pass}='xxxxxxxx'; $ua->env_proxy(); my $URL="http://www.dlugosz.com"; my $request = HTTP::Request->new('GET', $URL); my $response = $ua->request($request); print "Code: ", $response->code(), ".\n"; print "Content type: ", $response->headers()->content_type(), ".\n"; print $response->content();

I get back content telling me to try the password again, with a code 407. I tried setting the $ENV variables within the script as shown to make sure the shell wasn't munging my characters when I put them in the environment. The username is clear. I tried variations on the proxy name, such as leaving off the http:// part, but that doesn't get as far—since I'm getting a message from the proxy, I figure that must be to its liking.

Window NT 4.0 SP6a, ActiveState Perl build 626

Anything else I should try?

—John

Edit: chipmunk 2001-05-31

Replies are listed 'Best First'.
(jeffa) Re: LPW and proxies
by jeffa (Bishop) on Jun 01, 2001 at 01:57 UTC
    You can try using the methods available from LWP::UserAgent and HTTP:Request: (from perldoc lwpcook)
    use LWP::UserAgent; my $ua = LWP::UserAgent->new; $ua->proxy(['http', 'ftp'] => 'http://proxy.myorg.com'); my $req = HTTP::Request->new('GET',"http://www.perl.com"); $req->proxy_authorization_basic("proxy_user", "proxy_password"); my $res = $ua->request($req); print $res->content if $res->is_success;

    Jeff

    R-R-R--R-R-R--R-R-R--R-R-R--R-R-R--
    L-L--L-L--L-L--L-L--L-L--L-L--L-L--
    
      Adding the proxy_authorization_basic call works. In fact, simply saying

      $request->proxy_authorization_basic($ENV{HTTP_proxy_user}, $ENV{HTTP_p +roxy_pass});

      works too, so the info is in the env just fine. It's just not working the way the manual says it should, for some reason??

      —John

Re: LPW and proxies
by Anonymous Monk on Jun 01, 2001 at 02:25 UTC
    $ENV{'http_proxy'} = "192.168.0.254:8080"; Works fine for me !