我使用HTTP::Tiny+IO::Socket::Socks::Wrapper通过Socks代理发送HTTP请求。除了超时选项外,一切都很好。当只使用IO::Socket::Socks而不使用HTTP::Tiny时,超时有效。
没有HTTP::Tiny和不存在的代理触发超时的示例:
my $t = time;
my $sock = IO::Socket::Socks->new(
ProxyAddr => '4.5.6.7',
ProxyPort => 1080,
ConnectAddr => 'www.google.com',
ConnectPort => 80,
Timeout => 3
) or print "connection failed or timed outn";
print "time: " . (time - $t) . "n";
输出:
connection failed or timed out
time: 3.00517201423645
HTTP::Tiny:示例
my $t = time;
my $http = wrap_connection(
HTTP::Tiny->new(timeout => 3), {
ProxyAddr => '4.5.6.7',
ProxyPort => 1080,
Timeout => 3
}
);
my $r = $http->get("http://www.google.com");
print "connection failed or timed outn" unless $r->{success};
print "time: " . (time - $t) . "n";
输出:
connection failed or timed out
time: 21.0282030105591
为什么第二个示例在3秒钟后没有超时?
这是一个错误,现在似乎已经修复。新版本将很快上传到CPAN。现在,您可以从github repo获得固定版本。