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

Hello, I am really just a starter and I succeed in making a script that downloads the url specified but now I would like to add a proxy with an ip and a port for instance this ip 109.191.37.193 with port 3128.. Is there someone who can help me out a bit? Thanks in advance, PS this is what I already got
#!/usr/local/bin/perl use LWP::UserAgent [search.cpan.org]; use HTTP::Request [kobesearch.cpan.org]; my $url = 'http://uploads.wouterds.be/download/63/'; my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeou +t => 10); my $header = HTTP::Request->new(GET => $url); my $request = HTTP::Request->new('GET', $url, $header); my $response = $agent->request($request); # Check the outcome of the response if($response->is_success){ print "Download ok\n"; } elsif($response->is_error){ print "Error:$url\n"; print $response->error_as_HTML; }

Replies are listed 'Best First'.
Re: Use proxy in perl script
by Corion (Patriarch) on Aug 31, 2011 at 07:58 UTC

    You are using:

    my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeou +t => 10);

    How could the documentation of LWP::UserAgent be made more clear so the meaning of env_proxy does not confuse you?

Re: Use proxy in perl script
by CountZero (Bishop) on Aug 31, 2011 at 10:15 UTC
    Unless you want to mess with environment variables, try $agent->proxy('http', 'http://109.191.37.193:3128/');, and set the env_proxy key to zero. You can also delete that key, but explicitly setting it to zero (which is the default value) serves as a good reminder that you are not using environment variables.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Use proxy in perl script
by Anonymous Monk on Aug 31, 2011 at 07:55 UTC