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("", "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 (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'));
        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