使用 Perl 的 HTTP 请求到 utf-8 URI(里面有一些非 ascii 字符)会抛出 404 Not Found 错误
HTTP request with Perl to a utf-8 URI (some non-ascii chars inside) throws a 404 Not Found error
我正在尝试请求一个 URL,它有一些非 ASCII 字符,例如:http://perry.wikia.com/wiki/Página_principal,它有一个 á
符号。
我试过 LWP::UserAgent 但它抛出 404 未找到错误:
#!/usr/bin/perl
use utf8;
use LWP::UserAgent;
use Encode qw(decode encode);
my $br = LWP::UserAgent->new;
#~ my $url = 'http://perry.wikia.com/wiki/Página_principal'; # doesn't work either
my $url = encode('UTF-8','http://perry.wikia.com/wiki/Página_principal');
my $response = $br->get($url);
if ($response->{success}) {
my $html = $response->{content};
} else {
die "Unexpected error requesting $url : " . $response->status_line;
}
我也试过 HTTP::Tiny,同样的结果:
#!/usr/bin/perl
use utf8;
use HTTP::Tiny;
use Encode qw(decode encode);
my $url = 'http://perry.wikia.com/wiki/Página_principal';
#~ my $url = encode('UTF-8','http://perry.wikia.com/wiki/Página_principal'); # doesn't work either
my $response = HTTP::Tiny->new->get($url);
if ($response->{success}) {
my $html = $response->{content};
} else {
die "Unexpected error requesting $url : " . $response->{status};
}
这不是任何 Perl 模块中的错误。 URL 实际上 return 404。
我正在尝试请求一个 URL,它有一些非 ASCII 字符,例如:http://perry.wikia.com/wiki/Página_principal,它有一个 á
符号。
我试过 LWP::UserAgent 但它抛出 404 未找到错误:
#!/usr/bin/perl
use utf8;
use LWP::UserAgent;
use Encode qw(decode encode);
my $br = LWP::UserAgent->new;
#~ my $url = 'http://perry.wikia.com/wiki/Página_principal'; # doesn't work either
my $url = encode('UTF-8','http://perry.wikia.com/wiki/Página_principal');
my $response = $br->get($url);
if ($response->{success}) {
my $html = $response->{content};
} else {
die "Unexpected error requesting $url : " . $response->status_line;
}
我也试过 HTTP::Tiny,同样的结果:
#!/usr/bin/perl
use utf8;
use HTTP::Tiny;
use Encode qw(decode encode);
my $url = 'http://perry.wikia.com/wiki/Página_principal';
#~ my $url = encode('UTF-8','http://perry.wikia.com/wiki/Página_principal'); # doesn't work either
my $response = HTTP::Tiny->new->get($url);
if ($response->{success}) {
my $html = $response->{content};
} else {
die "Unexpected error requesting $url : " . $response->{status};
}
这不是任何 Perl 模块中的错误。 URL 实际上 return 404。