我正在使用REST::Client并且我的代码因 SSL 错误而失败。
这是代码:
#!usr/bin/perl -w
use strict;
use REST::Client;
my $client = REST::Client->new();
$client->GET("https://something/api/sessions");
print $client->responseContent();
Run Code Online (Sandbox Code Playgroud)
这是输出:
WP::Protocol::https::Socket: SSL connect attempt failed with unknown error error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed at /usr/local/share/perl/5.10.1/LWP/Protocol/http.pm line 51.
Run Code Online (Sandbox Code Playgroud)
我知道问题所在。REST::Client无法忽略 SSL 证书。
curl当我不使用“-k”选项时,我得到完全相同的错误:
这是 curl 命令:
curl -i -H "Accept:application/*+xml;version=1.5" -u "username@system:password" -X post https://something/api/sessions
Run Code Online (Sandbox Code Playgroud)
这是 curl 输出(错误):
curl: (60) SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Run Code Online (Sandbox Code Playgroud)
但是,如果我在 curl 命令中添加“-k”,那么它就可以正常工作。
从 curl 的手册页,这里是“-k”的解释:
(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers.
Run Code Online (Sandbox Code Playgroud)
题:
那么,如何REST::Client忽略 SSL 证书?或者还有其他优雅的工作方式吗?我浏览了REST::Client关于 CPAN的文档,但它没有谈论这个。
谢谢。
我通过添加以下行使其工作:
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;
Run Code Online (Sandbox Code Playgroud)
参考: https: //splash.riverbed.com/docs/DOC-1602