in reply to Re: Not sure how to use HTTP::Tiny
in thread Not sure how to use HTTP::Tiny

use HTTP::Tiny; my $url = 'https://<my-url>'; my $headers = { Accept => "application/json", 'Content-Type' => "application/json", Authorization => "user:password" }; my $response = HTTP::Tiny->new->get($url, { headers => $headers }); if ($response->{success}) { my $html = $response->{content}; print "$html\n"; } else { print "failure: $response->{status}\n"; } This prints 401

Replies are listed 'Best First'.
Re^3: Not sure how to use HTTP::Tiny
by huck (Prior) on May 21, 2018 at 18:18 UTC

    once when i was forced to do authorization myself (via tkx sockets) i used

    if ($args{user} || $args{password}) { use MIME::Base64; $tkxf_auth='Authorization: Basic '.encode_base64($args{user}.':' +.$args{password},''); }
    which would make your call
    use MIME::Base64; my $headers = { Accept => "application/json", 'Content-Type' => "application/json", Authorization => 'Authorization: Basic '.encode_base +64($args{user}.':'.$args{password},'') };

    Edit: the real userid/passwords are stored in the hash %args under keys userid and password!

      I get the same result (401) with my $headers = { Accept => "application/json", 'Content-Type' => "application/json", Authorization => "Authorization: Basic ".encode_base +64("user:password") };

        Try

        use MIME::Base64; my $headers = { Accept => "application/json", 'Content-Type' => "application/json", Authorization => "Basic ".encode_base64("user:password"), };
        poj
Re^3: Not sure how to use HTTP::Tiny
by Corion (Patriarch) on May 21, 2018 at 17:54 UTC
    Authorization => "user:password"

    Are you sure that you want to send an "Authorization" header with exactly user:password in it?

    The usual format for Authorization headers says that it has at least a type in front of it:

    Authorization: <type> <credentials>

    So maybe now is the time to look at what data Curl would try to send over the network and then try to replicate that using Perl / HTTP::Tiny.

      given that my alternative is system("curl --insecure --user user:password -XGET -H Content-type:app +lication/json -H Accept:application/json https://<my-url>") in a perl script, it matters little. All of this will be executed on an internal secured network.