perl lwp 超时问题

111 篇文章 33 订阅 ¥39.90 ¥99.00
这篇博客探讨了在使用Perl的LWP::UserAgent模块时遇到的超时问题。示例代码显示设置了10秒的超时限制,但当服务端在规定时间内未响应时,请求导致超时并返回'500 read timeout'错误。通过运行脚本的时间分析,可以看到实际超时情况符合设定。
摘要由CSDN通过智能技术生成
lwp 超时问题:

jrhmpt01:/root/async# cat a1.pl 
use  LWP::UserAgent;
use utf8;
use DBI;
use POSIX;
use Data::Dumper;
use HTML::TreeBuilder;
  use HTML::TreeBuilder::XPath;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
$ua->agent("Mozilla/8.0");
#my $response = $ua->get('http://data.10jqka.com.cn/financial/yjyg/date/2016-03-31/board/ALL/field/enddate/order/desc/page/1/ajax/1/');
#my $response = $ua->get('http://data.10jqka.com.cn/financial/yjyg/');


my $response = $ua->get('http://120.55.11x.6:3000/api/env?ip=192.168.32.101');
if ($response->is_success) {
print   $response->decoded_content;  # or whatever
}
else
{print   $response->decoded_content; };


设置超时时间为 $ua->timeout(10);


结果如下:
jrhmpt01:/root/async# time perl a1.pl
500 read timeout

real	0m10.192s
user	0m0.169s
sys	0m0.016s

服务端在10秒内没返回,就超时



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

scan724

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值