Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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 (Monsignor) 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("www.example.com:80", "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("www.example.com:80", "Some Realm", "foo", "secret");

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

Re: lwp authorization
by hippo (Abbot) 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'));
        poj
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1190526]
Approved by Athanasius
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2017-11-18 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?