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

    My problem is that I always get http 403 error, asking for admin account even if i already passed the correct admin account.

    What kind of authentication scheme protects this url?

Re: HTTP request
by locked_user sundialsvc4 (Abbot) on Oct 14, 2015 at 12:45 UTC

    And also, in all cases like these, look at what exactly is the actual HTTP exchange ... byte by byte ... that is taking place between these two parties.   You can use Perl logging facilities, or an external tool like WireShark (if not encrypted).   It’s way too easy to think that you know what is being passed, but to be mistaken, and thereby to waste way too much time guessing when you could have looked.   :-/   (Certainly, mea culpa on this one!)   Compare this to external documentation of what the exchange should be.