如果我使用wget
从 geonames.org 服务器检索某些内容,它会报告两个 IP 地址,第一个失败但它从第二个获取它:
Resolving ws.geonames.org (ws.geonames.org)... 5.9.41.208, 176.9.107.169
Connecting to ws.geonames.org (ws.geonames.org)|5.9.41.208|:80... failed: Connection refused.
Connecting to ws.geonames.org (ws.geonames.org)|176.9.107.169|:80... connected.
HTTP request sent, awaiting response... 200 OK
但不幸的是,我必须通过 perl 使用 LWP::UserAgent 和 HTTP::Request 来访问它。如果第一个失败,我怎样才能让他们尝试第二个 IP?
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(
GET =>
"http://ws.geonames.org/countrySubdivision?lat=$lat&lng=$long&radius=$radius&username=xyzzy");
my $res = $ua->request($req);