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

Hi, I'm having problems getting a simple perl program to work (a learning curve for me)

I am on a Linux host and if I do this

wget 'https://mytarget.com:9999/Mode/schedule/Host/myhost?User=myuser&Token=XXXXX-AXXX-4812-B123-XXXXXXXXC&type=xml'

I get

--2019-09-18 13:07:18-- 'https://mytarget.com:9999/Mode/schedule/Host/ +myhost?User=myuser&Token=XXXXX-AXXX-4812-B123-XXXXXXXXC&type=xml Resolving mytarget.com... xxx.xxx.xxx.xxx Connecting to mytarget.com|xxx.xxx.xxx.xxx|:9999... connected. HTTP request sent, awaiting response... 200 OK Length: 371 [application/xml] Saving to: .....

I am trying to convert this to perl so I am using this code

use strict; use warnings; use Data::Dumper; use feature 'say'; use HTTP::Tiny; my $Client = HTTP::Tiny->new(); my @urls = ( 'https://mytarget.com:9999/Mode/schedule/Host/myhost?User=myuser&T +oken=XXXXX-AXXX-4812-B123-XXXXXXXXC&type=xml', 'https://notarealsite.com:9999', ); for my $url (@urls) { my $response = $Client->get($url); say $url, ": ", $response->{status}; }

But when I run it I get

https://mytarget.com:9999/Mode/schedule/Host/myhost?User=myuser&Token= +XXXXX-AXXX-4812-B123-XXXXXXXXC&type=xml: 599 https://notarealsite.com:9999: 599

My understanding is that this means it's not able to contact the target

It's undoubtedly something simple I have missed but what am I doing wrong ?

Replies are listed 'Best First'.
Re: url issues using HTTP::Tiny
by haukex (Archbishop) on Sep 18, 2019 at 13:40 UTC

    As per the HTTP::Tiny docs, a status code of 599 is a fake code that indicates an internal error, and you should check $response->{content} for the actual error message. Since you're accessing SSL sites, you also want to make sure you have IO::Socket::SSL 1.56 or greater and Net::SSLeay 1.49 or greater installed.

      Thanks this is the info that I was after. I am however a bit confused since I thought that HTTP::Tiny is part of the core perl distribution. I'm using 5.14.2 . So it ships without all the dependant modules ?

        https support is not in the Perl core.

        Don't worry! HTTP::Tiny will rot bits as webmasters implement HTTPS Everywhere! except for the backlash of hip retro unencrypted sites! Then one day HTTP::Tiny, after years of recommendations followed by years of disillusionment [YOU ARE HERE] followed by years of disparagement, will be unceremoniously deprecated and REMOVED FROM THE PERL CORE!

        If it could happen to CGI, it will probably happen to HTTP::Tiny 🔋🗑

        UNLESS someone rescues HTTP::Tiny to evolve some sort of fallback functionality along the lines of HTTP::Any like this silly core one-liner, when fed an https url on an https-less perl, will fail and fallback on a random selection of wget or curl (or, like, all known https clients on every operating system?):

        perl -MIPC::Cmd=can_run,run -MHTTP::Tiny -le'@c=({wget=>"wget -O-"},{c +url=>"curl"});$u=shift;$r=HTTP::Tiny->new->get($u);if($r->{status}==5 +99){($a,$b)=%{$c[rand@c]};if(my $cmd=can_run($a)){if(scalar run(comma +nd=>"$b $u",buffer=>\my $data)){print"$data\n$cmd"}}}else{print"$r->{ +content}\ntiny"}' "https://www.perlmonks.org"
        perl -MIPC::Cmd=can_run,run -MHTTP::Tiny -le' @c=({wget=>"wget -O-"},{curl=>"curl"}); $u=shift; $r=HTTP::Tiny->new->get($u); if($r->{status}==599){ ($a,$b)=%{$c[rand@c]}; if(my $cmd=can_run($a)){ if(scalar run(command=>"$b $u",buffer=>\my $data){ print"$data\n$cmd" } } } else{print"$r->{content}\ntiny"}' "https://www.perlmonks.org"
        Let's fix it!
Re: url issues using HTTP::Tiny
by marto (Cardinal) on Sep 18, 2019 at 13:32 UTC

    HTTP 599 suggests a network timeout. curl has a 2 minute timeout by default, HTTP::Tiny has a default of 1 minute, perhaps try providing a longer timeout attribute in your constructor?