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

2019-02-18 11:08发布

问题:

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";
}

回答1:

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/' );


标签: perl proxy lwp