2009-02-12 48 views
3

如何向此脚本添加代理支持?如何使用LWP :: Simple处理代理服务器?

use LWP::Simple; 

$url = "http://stackoverflow.com"; 
$word = "how to ask"; 
$content = get $url; 
if($content =~ m/$word/) 
{ 
print "Found $word"; 
} 
+0

如果你简直一派这一点,非常先打会告诉你答案! – 2009-02-12 18:23:43

回答

12

访问底层的LWP :: UserAgent对象并设置代理。 LWP ::简单的出口$ua变量,所以你可以这样做:

 
use LWP::Simple qw($ua get); 
$ua->proxy('http', 'http://myproxy.example.com'); 
my $content = get('http://www.example.com/');