Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

lwp authorization

by bigup401 (Pilgrim)
on May 18, 2017 at 12:17 UTC ( [id://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 (Archbishop) 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 (Bishop) 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
        A reply falls below the community's threshold of quality. You may see it by logging in.
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
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1190526]
Approved by Athanasius
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 17:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found