bigup401 has asked for the wisdom of the Perl Monks concerning the following question:

am trying to parse this curl but am getting an hex response LOL

curl code

curl -v -u <AUTH_ID>:<AUTH_TOKEN> https://url/ \ -H 'content-type: application/json' \ -d '{"destination": ["to"], \ "source": "from", \ "text": "Sent from curl"}'

my code

$to = "John"; $from = "John"; $msg = "Hi Man"; my $url = "https://url"; my $json = encode_json { destination => $to, source => $from, text => $msg, }; my $http = HTTP::Tinyish->new( default_headers => { AUTH_ID => '9eafe236623bf2b5c2357d43333d3bba77ceed71', AUTH_TOKEN => '9eafe236623bf2b5c2357d43333d3bba77ceed71', } ); my $response = $http->post( $url => { content => $json, headers => { 'Content-Type' => 'application/json' }, }); $reponr = ( decode_json $response->{'content'} ); print "$reponr\n";

Replies are listed 'Best First'.
Re: curl problem
by haukex (Archbishop) on Jul 08, 2018 at 14:16 UTC

    I don't think the translation of curl -u <AUTH_ID>:<AUTH_TOKEN> to default_headers => { AUTH_ID=>..., AUTH_TOKEN=>... } is correct. In curl, -u specifies a username/password for authentication, the equivalent in HTTP::Tiny (and therefore HTTP::Tinyish, I assume) is to include a username:password in the URL - but it supports Basic Authentication only. See the HTTP::Tiny docs for details, but if you have to support Digest Auth, you might need to switch to something like LWP.

      sure u-username v-password

        true, i think i need to do it with Basic Authentication, coz thats the reponse i get when i put api url in browser