I want to get the content of https://translate.google.cn, however, Cro::HTTP::Client
and HTTP::UserAgent
just stucks, and WWW
get the content, I don't know why.
If I change the $url
to https://raku.org, all three modules works fine:
my $url = "https://translate.google.cn";
use Cro::HTTP::Client;
my $resp = await Cro::HTTP::Client.new(
headers => [
User-agent => 'Cro'
]
).get($url);
say await $resp.body-text();
use HTTP::UserAgent;
my $ua = HTTP::UserAgent.new;
$ua.timeout = 30;
my $response = $ua.get($url);
if $response.is-success {
say $response.content;
} else {
die $response.status-line;
}
)
use WWW;
say get($url)
Did I miss something? Thanks for suggestion for me.
For me
HTTP::UserAgent
works andCro::HTTP::Client
gets stuck. If you wish to debug things further both modules have a debug option:raku -MHTTP::UserAgent -e 'my $ua = HTTP::UserAgent.new(:debug); say $ua.get("https://translate.google.cn").content'
CRO_TRACE=1 raku -MCro::HTTP::Client -e 'my $ua = Cro::HTTP::Client.new(); say $ua.get("https://translate.google.cn").result.body-text.result'
WWW
also works for me. It is surprising it works for you since it is backed byHTTP::UserAgent
( which does not work for you ). Here is itsget
method to show you how it usesHTTP::UserAgent
: