Bootstrap FreeKB - Perl (Scripting) - insecure SSL certificates with the LWP::UserAgent REST API module
Perl (Scripting) - insecure SSL certificates with the LWP::UserAgent REST API module

Updated:   |  Perl (Scripting) articles

The LWP::UserAgent module can be used to issue a curl request and return the response. If the connection produces SSL failures, and you trust the URL being requested, ssl_opts verify_hostname can be set to 0 (disabled).

For example, let's say a request to www.example.com/api should return "Hello World", and Dumper can be used to display the response.

#!/usr/bin/perl
use strict;
use warning;
use LWP::UserAgent;
use Data::Dumper;

my $ua = LWP::UserAgent->new;
$ua->ssl_opts( verify_hostname => 0 );
my $request = HTTP::Request->new(GET => "http://www.example.com/api");
my $response = $ua->request($request);

print Dumper $response;

 

Something like this should be returned.

$VAR1 = bless( {
                 '_protocol' => 'HTTP/1.1',
                 '_content' => 'Hello World',
                 '_rc' => '200'
});

 

And here is how you would print only the content.

print $response->decoded_content;



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 78301b in the box below so that we can be sure you are a human.