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); }