无法在Perl中使用HTTPS使用服务器的REST api

无法在Perl中使用HTTPS使用服务器的REST api,perl,api,http,post,https,Perl,Api,Http,Post,Https,我尝试了很多不同的代码片段来让它工作,但我一辈子都无法让它工作。这是我拥有的最新代码。我收到的错误消息是“无法连接到172.16.77.247:443” 请帮助我连接。谢谢大家! #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $server_endpoint = "https://172.16.77.247/api/reference_d

我尝试了很多不同的代码片段来让它工作,但我一辈子都无法让它工作。这是我拥有的最新代码。我收到的错误消息是“无法连接到172.16.77.247:443”

请帮助我连接。谢谢大家!

#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;


my $ua = LWP::UserAgent->new();

my $server_endpoint = "https://172.16.77.247/api/reference_data/sets/bulk_load/myDataSet";
my $req = HTTP::Request->new(POST => $server_endpoint);

# add headers data to HTTP request
$req->header('Version' => '4.0', 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'SEC' => 'f6a2e2b5-d3f3-4dc2-a51a-5bf65fbec9e7');

# add content to HTTP request body
my $post_data = '["192.168.0.10","192.168.0.11"]';
$req->content($post_data);


# issue HTTP request
my $response = $ua->request($req);

# process response
if ($response->is_success) {
    my $message = $response->decoded_content;
    print "Received reply: $message\n";
}
else {
    print "HTTP POST error code: ", $response->code, "\n";
    print "HTTP POST error message: ", $response->message, "\n";
}

你能
wget
这个地址吗?您是否安装了
LWP::Protocol::https
?SSL证书有什么问题吗?我真的能理解,哎呀。我的VPN已断开连接,这就是我事先被拒绝连接的原因。我收到一个错误,无法验证证书。证书名称中的匹配失败,也许这就是问题所在?是的,这确实是一个问题。SSL要求证书与主机名匹配。您可能会使用本地
/etc/hosts
条目或类似条目伪造它(出于测试目的)。这可能有助于cert错误,可接受答案中的参数可以传递给LWP:Add
use IO::Socket::SSL应修复警告。