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秒内没返回,就超时
转载于:https://www.cnblogs.com/zhaoyangjian724/p/6200173.html