我正在使用带有REST :: Client的perl v5.10.0并尝试连接到Censys API。 这是我的代码:
#!/usr/bin/env perl -w
use strict;
use warnings;
use MIME::Base64;
use REST::Client;
use JSON;
my $host = 'https://www.censys.io/api/v1/search/ipv4';
my $api_id = 'foo';
my $secret = 'bar';
my $json = '{"query":"Apache"}';
my $client = REST::Client->new(host => $host);
# tryed both, doesnt work
# my $encoded_auth = encode_base64("$api_id:$secret", '');
my $encoded_auth = ("$api_id:$secret");
$client->POST('$json',
{'Authorization' => "Basic $encoded_auth",
'Content-Type' => 'application/json',
'Accept' => 'application/json'});
print 'Response: ' . $client->responseContent() . "\n";
print 'Response status: ' . $client->responseCode() . "\n";
foreach ( $client->responseHeaders() ) {
print 'Header: ' . $_ . '=' . $client->responseHeader($_) . "\n";
}
当我运行代码时,我收到以下错误:
Response: Can't connect to www.censys.io:443 (No route to host)
Response status: 500
Header: Content-Type=text/plain
Header: Client-Date=Mon, 25 Sep 2017 15:31:44 GMT
Header: Client-Warning=Internal response
为什么有(无主机路由),当我尝试使用wget时它可以工作。 任何帮助将不胜感激。