Bootstrap FreeKB - Perl (Scripting) - curl HTTPS (LWP::UserAgent, LWP::Protocol::https)
Perl (Scripting) - curl HTTPS (LWP::UserAgent, LWP::Protocol::https)

Updated:   |  Perl (Scripting) articles

The LWP::UserAgent module can be used to issue a curl request and return the response. When the target is an HTTPS URL, the LWP::Protocol::https module will also need to be installed.

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

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

my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new(GET => "https://www.example.com/foo");
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 564f52 in the box below so that we can be sure you are a human.