REST :: Client: how to ignore SSL certificates

I work with REST::Client , and my code crashes with an SSL error.

Here is the code:

 #!usr/bin/perl -w use strict; use REST::Client; my $client = REST::Client->new(); $client->GET("https://something/api/sessions"); print $client->responseContent(); 

and here is the result:

 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. 

I know the problem. REST::Client cannot ignore SSL certificate.

I get the same error with curl when I do not use the -k option:

here is the curl command:

 curl -i -H "Accept:application/*+xml;version=1.5" -u " username@system :password" -X post https://something/api/sessions 

and here are the outputs of curl (Error):

 curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 

However, if I add "-k" to the curl command, then it will work fine.

From the curl man page, here is the explanation of "-k":

 (SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers. 

Question:

So, how do I make REST::Client ignore the SSL certificate? OR is there another elegant way to work? I looked at the REST::Client documentation on CPAN, but it says nothing.

Thanks.

+4
source share
2 answers

I started working by adding the line below:

 $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; 

Link: https://splash.riverbed.com/docs/DOC-1602

+3
source

I found that the option does not completely fix the problem in LWP 6.x. For me it worked:

 # 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); 
+2
source

Source: https://habr.com/ru/post/1486531/


All Articles