perl http request
#!/usr/bin/env perl
use strict;
use warnings;
use Encode qw(encode_utf8);
use HTTP::Request ();
use JSON::MaybeXS qw(encode_json);
my $url = 'https://www.example.com/api/user/123';
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);
4.33
6
#!/usr/bin/env perl use strict;use warnings; use Encode qw(encode_utf8);use HTTP::Request ();use JSON::MaybeXS qw(encode_json); my $url = 'https://www.example.com/api/user/123';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);
Thank you!
6
0
Are there any code examples left?
New code examples in category Perl
-
Perl 2022-01-31 06:16:22 perl format decimal 2 places not rounding
-
Perl 2022-01-30 18:35:07 perl id number validation south africa
-
Perl 2022-01-22 12:46:02 perl add key value pair to hash
-
Perl 2021-11-22 01:55:21 unique in perl
-
Perl 2021-11-13 15:55:08 perl lowercase
-
Perl 2021-11-11 03:30:19 perl write to file
-
Perl 2021-11-06 22:53:11 perl for loop
-
Perl 2021-11-05 17:26:13 perl sprintf YYYYMMDD sample