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