Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install LWP::Protocol::https?

Tags:

perl

lwp

I created a Perl script to run an https task. When I run it I get the error LWP::Protocol::https not installed.

I cannot figure out, or find a tutorial or command on how exactly to install LWP::Protocol::http. Anyone have any idea how to install it? Installing LWP was quite easy.

I have installed LWP and installed Crypt-SSLeay, however I still get the error. Here is my code:

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;


# set custom HTTP request header fields

my $req = HTTP::Request->new(PUT => "https://thesite.com");

$req->header('Authorization' => 'myauth');
$req->header('Accept' => 'JSON:Application/JSON');
$req->header('Content-Type' => 'JSON:Application/JSON');
$req->header('Host' => 'api.thesite.com');

$req->content('Text' => 'thetext');



my $resp = $ua->request($req);
if ($resp->is_success) {
    my $message = $resp->decoded_content;
    print "Received reply: $message\n";
}
else {
    print "HTTP POST error code: ", $resp->code, "\n";
    print "HTTP POST error message: ", $resp->message, "\n";
}
like image 566
CRAIG Avatar asked Jan 14 '14 20:01

CRAIG


People also ask

What is LWP :: Simple?

LWP::SimpleReturns the contents of the URL specified by $url. Upon failure, get( ) returns undef. Other than returning undef, there is no way of accessing the HTTP status code or headers returned by the server.

What is LWP :: UserAgent?

LWP::UserAgent is a class for “virtual browsers,” which you use for performing requests, and HTTP::Response is a class for the responses (or error messages) that you get back from those requests.


2 Answers

sudo yum install perl-LWP-Protocol-https fixed issue for me.

like image 118
Chathuranga Abeyrathna Avatar answered Sep 27 '22 20:09

Chathuranga Abeyrathna


Running sudo cpan install LWP::Protocol::https fixed this for me.

like image 20
FCTW Avatar answered Sep 27 '22 20:09

FCTW