如何使用 LWP::Simple 处理代理服务器? [英] How can I handle proxy servers with LWP::Simple?

查看:56
本文介绍了如何使用 LWP::Simple 处理代理服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为该脚本添加代理支持?

使用 LWP::Simple;$url = "http://stackoverflow.com";$word = "怎么问";$content = 获取 $url;if($content =~ m/$word/){打印找到 $word";}

解决方案

访问底层 LWP::UserAgent 对象并设置代理.LWP::Simple 导出 $ua 变量,所以你可以这样做:

<前>使用 LWP::Simple qw( $ua get );$ua->proxy('http', 'http://myproxy.example.com');我的 $content = get( 'http://www.example.com/' );

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

解决方案

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

这篇关于如何使用 LWP::Simple 处理代理服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆