Perl 脚本使用代理凭据监控 URL?
请帮助解决以下代码,这在我们的环境中不起作用。
use LWP;
use strict;
my $url = 'http://google.com';
my $username = 'user';
my $password = 'mypassword';
my $browser = LWP::UserAgent->new('Mozilla');
$browser->credentials("172.18.124.11:80","something.co.in",$username=>$password);
$browser->timeout(10);
my $response=$browser->get($url);
print $response->content;
输出:
无法连接到 google.com:80(超时)
LWP::Protocol::http::Socket: connect: timeout at C:/Perl/lib/LWP/Protocol/http.pm line 51。
操作系统:windows XP
问候,Gaurav
Please help on the following code, this is not working in our environment.
use LWP;
use strict;
my $url = 'http://google.com';
my $username = 'user';
my $password = 'mypassword';
my $browser = LWP::UserAgent->new('Mozilla');
$browser->credentials("172.18.124.11:80","something.co.in",$username=>$password);
$browser->timeout(10);
my $response=$browser->get($url);
print $response->content;
OUTPUT :
Can't connect to google.com:80 (timeout)
LWP::Protocol::http::Socket: connect: timeout at C:/Perl/lib/LWP/Protocol/http.p m line 51.
OS: windows XP
Regards, Gaurav
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否有 172.18.124.11 的 HTTP 代理?我假设 LWP 没有使用代理。您可能想使用 env_proxy => 1 使用
new()
调用。您在这个问题中还有一个 mod-perl2 标签。如果此代码在 mod-perl2 内部运行,则
http_proxy
环境变量可能对该代码不可见。你可以检查这个,例如。通过打印$browser->proxy('http')
。或者只需使用
$browser->proxy('http', '172.18.124.11')
; 设置代理即可另外,我假设您没有打开
use warnings
,因为new()
需要一个哈希值,而不仅仅是一个字符串。 始终启用警告是个好主意。这将为您省去很多麻烦。Do you have a HTTP proxy at 172.18.124.11? I assume LWP is not using the proxy. You might want to use
env_proxy => 1
with thenew()
call.You also have a mod-perl2 tag in this question. If this code runs inside mod-perl2, it's possible that the
http_proxy
env variable is not visible to the code. You can check this eg. by printing$browser->proxy('http')
.Or just set the proxy with
$browser->proxy('http', '172.18.124.11')
;Also, I assume you don't have
use warnings
on, becausenew()
takes a hash, not just a string. It's a good idea to always enable warnings. That will save you lots of trouble.