artperl has asked for the wisdom of the Perl Monks concerning the following question:
hi, i'm trying to make a simple web api call to a server expecting a return of its status. Below is my code with the headers required by the server with rest api. My problem is that I always get http 403 error, asking for admin account even if i already passed the correct admin account. appreciate your help to check if i did something wrong in the coding. thanks.
use strict; use warnings; use LWP::UserAgent; use JSON; use HTTP::Request; use JSON::WebToken; my $ua = LWP::UserAgent->new; my $token = "5335cc306eba9214b73ec0643c6a0656"; my $payload = {"iat :" => 1443857906, "email :" => "user\@mydomain.com +", "password :" => "mypass"}; my $jwt_str = JSON::WebToken->encode($payload, $token); my $url = "http://192.168.0.100:8081/api/elasticubes/servers/localhost +/status"; my $req = HTTP::Request->new(GET => $url); $req->header('content-type' => 'application/json'); $req->header('x-auth-token' => $jwt_str); print "\n"; my $resp = $ua->request($req); if ($resp->is_success) { my $message = $resp->decoded_content; print "Received reply: $message\n"; } else { print "HTTP GET error code: ", $resp->code, "\n"; print "HTTP GET error message: ", $resp->message, "\n"; } print "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: HTTP request
by Anonymous Monk on Oct 14, 2015 at 09:02 UTC | |
|
Re: HTTP request
by locked_user sundialsvc4 (Abbot) on Oct 14, 2015 at 12:45 UTC |