Perl http request

In Perl, HTTP requests can be made using existing Perl modules.

In this article let’s discuss about how to make perl http request using LWP module. Let’s go through the following methods without any delay 🙂

Method 1:

#!/usr/bin/env perl 
use strict;
use warnings; 
use Encode qw(encode_utf8);
use HTTP::Request ();
use JSON::MaybeXS qw(encode_json);

my $url = '';
my $header = ['Content-Type' => 'application/json; charset=UTF-8'];
my $data = {foo => 'bar', baz => 'quux'};
my $encoded_data = encode_utf8(encode_json($data));
my $r = HTTP::Request->new('POST', $url, $header, $encoded_data);

# at this point, we could send it via LWP::UserAgent
# my $ua = LWP::UserAgent->new();
# my $res = $ua->request($r);

Hope the above methods works for you. Happy Learning and get back to us Anytime.

Realted Posts : Start service mongodb on mac