Issue
in shell script, when i want to run a curl command to upload, i just do this :
curl "http://website/event/collection" -H "Authorization:database IDhere-362ifd24-42jn422f-4214asf-ff424158ff" -d'{"time":"'"$epoch"'","event":{"Project_code": "'"$pname"'"}}'
but I want to convert all my codes from shell to perl. so any idea how can i run this $curl command in perl scripting ?
$epoch = time();
my $pname;
printf "Enter project name: "
$pname = <STDIN>;
chomp $pname
curl "http://website/event/collection" -H "Authorization:database IDhere-362ifd24-42jn422f-4214asf-ff424158ff" -d'{"time":"'"$epoch"'","event":{"Project_code": "'"$pname"'"}}'
Solution
i saw someone saying (Using https://corion.net/curl2lwp.psgi ) can generate the codes, but im not sure if thi is the correct way
#!perl
use strict;
use warnings;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new( 'send_te' => '0' );
my $r = HTTP::Request->new(
'POST' => 'http://website/event/collection',
[
'Accept' => '*/*',
'Authorization' =>
'database IDhere-362ifd24-42jn422f-4214asf-ff424158ff',
'Host' => 'website:80',
'User-Agent' => 'curl/7.55.1',
'Content-Length' => '52',
'Content-Type' => 'application/x-www-form-urlencoded'
],
"{\x22time\x22:\x22\x24epoch\x22,\x22event\x22:{\x22Project_code\x22: \x22\x24pname\x22}}"
);
my $res = $ua->request( $r, );
__END__
Created from curl command line
curl "http://website/event/collection" -H "Authorization:database IDhere-362ifd24-42jn422f-4214asf-ff424158ff" -d'{"time":"'"$epoch"'","event":{"Project_code": "'"$pname"'"}}'
Updated : Instead, just use this, it worked for me :
my $curl='curl whatevercodeshere'
Answered By - Wenhan Xiao