Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

lwp authorization

by bigup401 (Scribe)
on May 18, 2017 at 12:17 UTC ( #1190526=perlquestion: print w/replies, xml ) Need Help??
bigup401 has asked for the wisdom of the Perl Monks concerning the following question:

am still getting 401 Authorization Required bt my username and password is ok

my $req = HTTP::Request->new(POST => 'link'); $req->content_type('application/json'); $req->header('Authorization' => "Basic" .encode_base64('cv23gwyzqvur:t +y7idfphrkl')); $req->content('{"name":"john deo","country":"ca","email":"joshn@email. +com") my $res = $ua->request($req); if ($res->is_success) { print $res->content; } else { print $res->status_line; }

Replies are listed 'Best First'.
Re: lwp authorization
by haukex (Prior) on May 18, 2017 at 12:26 UTC
    $req->header('Authorization' => "Basic" .encode_base64('cv23gwyzqvur:ty7idfphrkl'));

    I would suggest that you don't try to set your own headers, have a look at the LWP::UserAgent docs for the credentials method instead, e.g.:

    $ua->credentials("", "Some Realm", "foo", "secret");

    Note that if you wanted to debug this, one way would be to use Wireshark to capture both a successful authentication via the browser and a failed one from your script.

      i know this method but cant use

      $ua->credentials("", "Some Realm", "foo", "secret");

      and gain post request to other url, its single request link

Re: lwp authorization
by hippo (Monsignor) on May 18, 2017 at 12:50 UTC
    $req->header('Authorization' => "Basic" .encode_base64('cv23gwyzqvur:ty7idfphrkl'));

    That does not match the HTTP/1.1 Basic Auth spec.

    Like haukex I cannot see why you have chosen not to use the already-available convenience method to achieve this. Can you explain your choice?

      because the api documentations tells me . authenticate by encoding your username and password to Base64 HTTP Basic Authorization

        # | space # V $req->header('Authorization' => "Basic " .encode_base64('cv23gwyzqvur: +t +y7idfphrkl'));
Re: lwp authorization
by Mr. Muskrat (Canon) on May 18, 2017 at 17:04 UTC

    If you are not willing to try what haukex, hippo and poj suggested then why did you bother to ask for help?

    Update: I forgot to include hippo initially.

      i tried it and fail

      i solved it. it was host problem

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1190526]
Approved by Athanasius
Discipulus must prepare some ammunitions: XML::Compile::SOAP but what the heck!

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2017-06-27 09:06 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (601 votes). Check out past polls.