使用Perl对utf-8URI(其中一些非ascii字符)的HTTP请求抛出404NotFound错误

使用Perl对utf-8URI(其中一些非ascii字符)的HTTP请求抛出404NotFound错误,perl,utf-8,uri,lwp,Perl,Utf 8,Uri,Lwp,我试图请求一个URL,它包含一些非ASCII字符,例如:有一个符号 我尝试使用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

我试图请求一个URL,它包含一些非ASCII字符,例如:有一个
符号

我尝试使用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实际上返回404。

您忽略了URI编码:
http://perry.wikia.com/wiki/P%C3%A1gina_principal
是您真正想要的。请检查,或者您确定此URL实际上不是404?Chrome和curl给了我404。你完全正确@oalders。我错过了它,因为从浏览器上看,网站似乎响应的是一个实际的页面,而不是404错误。@oalders没问题。好了