我正在使用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();
这是输出:
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.
我知道问题所在。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
下面是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
但是,如果我将"-k“添加到curl命令中,那么它就能正常工作。
在curl的手册页面中,有关于“-k”的解释:
(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers.
问题:
那么,如何使REST::Client
忽略SSL证书呢?或者还有其他优雅的工作方式吗?我看了一下CPAN上的REST::Client
文档,但是它没有提到这一点。
谢谢。
发布于 2013-06-17 07:01:40
发布于 2016-07-14 14:50:47
我发现这个选项并没有完全解决LWP 6.x中的问题。对我来说,这是可行的:
# setup rest client
my $client = REST::Client->new();
# don't verify SSL certs
$client->getUseragent()->ssl_opts(verify_hostname => 0);
$client->getUseragent()->ssl_opts(SSL_verify_mode => SSL_VERIFY_NONE);
https://stackoverflow.com/questions/17140642
复制相似问题