my $par_user = "123";
my $par_pass = "topsecret";
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,5,"RESTREQUEST","REST HTTP request start");
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/8.0"); # pretend we are very capable browser
$ua->timeout(30);
$ua->env_proxy;
my $req = HTTP::Request->new;
$req->header('content-type' => 'application/json');
$req->header('accept' => 'application/json');
$req->method($par_httpmethod);
$req->authorization_basic($par_user,$par_pass);
$req->uri($url_string);
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,5,"RESTREQUEST","Method: $par_httpmethod");
LOG_MSG($par_log_fh,$par_vbse,"v",$par_lglvl,7,"RESTREQUEST","Authorisation: $par_user,$par_pass");
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,5,"RESTREQUEST","URL: $url_string");
my $response = $ua->request($req);
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,5,"RESTREQUEST","ssss");
if ($response->is_success)
{
$http_status_code = $response->code;
$http_decoded = $response->decoded_content;
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,5,"RESTREQUEST","HTTP request successful");
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,5,"RESTREQUEST","HTTP status code: $http_status_code");
LOG_MSG($par_log_fh,$par_vbse,"v",$par_lglvl,7,"RESTREQUEST","HTTP decoded: $http_decoded");
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,5,"RESTREQUEST","REST HTTP request finished");
return ($http_status_code,$http_decoded);
}
else
{
$http_status_code = $response->code;
$http_decoded = $response->decoded_content;
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,3,"RESTREQUEST","HTTP request NOT successful");
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,3,"RESTREQUEST","HTTP status code: $http_status_code");
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,3,"RESTREQUEST","HTTP decoded: $http_decoded");
LOG_MSG($par_log_fh,$par_vbse,"n",$par_lglvl,3,"RESTREQUEST","REST HTTP request finished");
return ($http_status_code,$http_decoded);
}
####
2016.11.15,14:23:36,NOTICE,RESTGETPORTS,REST get ports start
2016.11.15,14:23:36,NOTICE,RESTREQUEST,REST HTTP request start
2016.11.15,14:23:36,NOTICE,RESTREQUEST,Method: GET
2016.11.15,14:23:36,NOTICE,RESTREQUEST,URL: http://10.3.3.3/ConfigurationManager/v1/objects/storages/800000058068/ports
####
2016.11.15,14:23:36,ERROR,GENERAL,Script died: Can't locate LWP/Authen/Session.pm in @INC (@INC contains: G:/development/HiCHperfpkg/bin\..\lib\modules G:/development/HiCHperfpkg/bin C:/Perl64/site/li
b C:/Perl64/lib .) at (eval 72) line 2.
####
print() on closed filehandle $fh at G:/development/HiCHperfpkg/bin\..\lib\modules/xxx_LOG.pm line 92.
2016.11.15,14:23:36,WARNING,GENERAL,Script warning: print() on closed filehandle $fh at G:/development/HiCHperfpkg/bin\..\lib\modules/xxx_LOG.pm line 92.
2016.11.15,14:23:36,NOTICE,RESTREQUEST,ssss
print() on closed filehandle $fh at G:/development/HiCHperfpkg/bin\..\lib\modules/xxx_LOG.pm line 92.
2016.11.15,14:23:36,WARNING,GENERAL,Script warning: print() on closed filehandle $fh at G:/development/HiCHperfpkg/bin\..\lib\modules/xxx_LOG.pm line 92.
2016.11.15,14:23:36,ERROR,RESTREQUEST,HTTP request NOT successful
print() on closed filehandle $fh at G:/development/HiCHperfpkg/bin\..\lib\modules/xxx_LOG.pm line 92.
2016.11.15,14:23:36,WARNING,GENERAL,Script warning: print() on closed filehandle $fh at G:/development/HiCHperfpkg/bin\..\lib\modules/xxx_LOG.pm line 92.
2016.11.15,14:23:36,ERROR,RESTREQUEST,HTTP status code: 401
print() on closed filehandle $fh at G:/development/HiCHperfpkg/bin\..\lib\modules/xxx_LOG.pm line 92.
2016.11.15,14:23:36,WARNING,GENERAL,Script warning: print() on closed filehandle $fh at G:/development/HiCHperfpkg/bin\..\lib\modules/xxx_LOG.pm line 92.
2016.11.15,14:23:36,ERROR,RESTREQUEST,HTTP decoded: {
"errorSource" : "/ConfigurationManager/v1/objects/storages/800000058068/ports",
"message" : "The Authorization HTTP header, which is required for authentication, is not specified.",
"solution" : "Specify the necessary value for the Authorization header.",
"messageId" : "KART30010-E"
####
2016.11.15,14:38:28,NOTICE,RESTGETSTORAGE,REST get storage start
2016.11.15,14:38:28,NOTICE,RESTREQUEST,REST HTTP request start
2016.11.15,14:38:28,NOTICE,RESTREQUEST,Method: GET
2016.11.15,14:38:28,NOTICE,RESTREQUEST,URL: http://10.0.1.11/ConfigurationManager/v1/objects/storages/
2016.11.15,14:38:49,NOTICE,RESTREQUEST,ssss
2016.11.15,14:38:49,ERROR,RESTREQUEST,HTTP request NOT successful
2016.11.15,14:38:49,ERROR,RESTREQUEST,HTTP status code: 500
2016.11.15,14:38:49,ERROR,RESTREQUEST,HTTP decoded: Can't connect to 10.70.4.14:80 (10060)
LWP::Protocol::http::Socket: connect: 10060 at C:/Perl64/lib/LWP/Protocol/http.pm line 51.
2016.11.15,14:38:49,ERROR,RESTREQUEST,REST HTTP request finished