1) Send http request using perl Using CURL
$jSONData = '{\"userId\": \"testuser@gmail.com\",
\"pwd\": \"testPassword\"
}';
$url = 'http://testingapi.com/v1/valUserCred';
my $curlCommand = "curl $url --header \"Accept: application/json\" --header \"Content-Type: application/json\" --header \"Access-Control-Allow-Origin: *\" --header \"Access-Control-Allow-Credentials: true\" --header \"Authorization: Basic $userKey\" --data \"".$jSONData."\"";
print STDERR "$curlCommand\n";
my $result = qx/$curlCommand/;
print STDERR Dumper($result);
----------------------------
2) Send http request using perl
my $url = 'http://testingapi.com/v1/valUserCred';
my $xml = <<"USER_XML";
<userid>testuser@gmail.com</userid>
<segment>testPassword</segment>
USER_XML
my $length = length($xml);
my $ua = LWP::UserAgent->new(env_proxy => 1, keep_alive => 1, timeout =>30);
my $req = HTTP::Request->new(POST =>$url);
$req->content($xml);
$req->header('Connection' => 'close', 'Content-length' => $length,'Content-Type'=>'text/xml', charset=>'utf-8');
my $res = $ua->request($req);
my $resData = $res->content;
my $refArray;
eval {
$refArray = new XML::Smart($resData);
};
if($@){
print_r($refArray);
}else{
print Dumper($refArray);
}
----------------------------------------------------------
Comments
Post a Comment