以下代码…
my $user_agent = LWP::UserAgent->new; my $request = HTTP::Request->new(GET => $url); my $response = $user_agent->request($request); if ($response->is_success) { print "OK\n"; } else { die($response->status_line); }
..会失败..
500 Can't connect to <hostname> (Bad hostname '<hostname>')
..如果$url中的主机名是仅IPv6地址(即:存在AAAA记录,但没有A记录).
我的问题是:
>如何在LWP中启用IPv6支持?
>如何配置LWP的“prefer-IPv4-over-IPv6”(A vs. AAAA)/“prefer-IPv6 over over IPv4”(AAAA vs.A)的设置?
解决方法
看起来你只需要使用
Net::INET6Glue::INET_is_INET6.引用它的例子:
use Net::INET6Glue::INET_is_INET6; use LWP::Simple; print get( 'http://[::1]:80' ); print get( 'http://ipv6.google.com' );