Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I handle proxy servers with LWP::Simple?

Tags:

proxy

perl

lwp

How can I add proxy support to this script?

use LWP::Simple;

$url = "http://stackoverflow.com";
$word = "how to ask";
$content = get $url;
if($content =~ m/$word/)
{
print "Found $word";
}
like image 607
localhost Avatar asked Dec 13 '22 05:12

localhost


1 Answers

Access the underlying LWP::UserAgent object and set the proxy. LWP::Simple exports the $ua variable so you can do that:

use LWP::Simple qw( $ua get );
$ua->proxy( 'http', 'http://myproxy.example.com' );
my $content = get( 'http://www.example.com/' );
like image 141
brian d foy Avatar answered Jan 05 '23 00:01

brian d foy