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

What is the current code you have and how does it fail to do what you want?

Most likely it is merely a matter of putting the user and password into the URL as basic authentication elements.

Replies are listed 'Best First'.
Re^2: Not sure how to use HTTP::Tiny
by plx (Initiate) on May 21, 2018 at 17:32 UTC
    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

      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") };
      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.