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

Ok Monks, I've been reading your wisdom for years, but alas I can't seems to find the answer to my current problem.

I need my Perl script to connect to a specific https page where JSON data is continuously streamed for parsing. So far I'm still trying to get connected to the page. Using the code below it will connect to the root page.

#!/usr/bin/perl use strict; use IO::Socket::SSL; # qw(debug3); # simple client my $cl = IO::Socket::SSL->new( PeerAddr => 'example.com:https', ) or die $!; print $cl "GET / HTTPS/1.0\r\n\r\n"; print <$cl>;

The one I need to connect to is in a sub directory with an access token with the code below gives me an "Invalid argument" error.

#!/usr/bin/perl use strict; use IO::Socket::SSL; # qw(debug3); # simple client my $cl = IO::Socket::SSL->new( PeerAddr => 'example.com/stream/report?token=4gaPemdzfM2M9 +XwMU9HT8MJSc6Fu6MlA:https', ) or die $!; print $cl "GET / HTTPS/1.0\r\n\r\n"; print <$cl>;

I know I'm missing something simple but for the life of me I can't figure it out.

Thanks for your help, Sean

Replies are listed 'Best First'.
Re: io::socket::ssl connecting to specific page on site
by huck (Prior) on Apr 12, 2017 at 02:50 UTC

    PeerAddr => 'example.com:https' is an address that can be looked up in a DNS and a port, PeerAddr => 'example.com/stream/report?token=4gaPemdzfM2M9XwMU9HT8MJSc6Fu6MlA:https', is not. Besides the name it includes part of the get substructure in what would be considered the ip addres subfield.

    use strict; use IO::Socket::SSL; # qw(debug3); # simple client my $cl = IO::Socket::SSL->new( PeerAddr => 'example.com:https', ) or die $!; print $cl "GET /stream/report?token=4gaPemdzfM2M9XwMU9HT8MJSc6Fu6M +lA HTTPS/1.0\r\n\r\n";

      > print $cl "GET /stream/report?token=4gaPemdzfM2M9XwMU9HT8MJSc6Fu6MlA HTTPS/1.0\r\n\r\n";

      That's interesting that this worked. Must be a forgiving server since the protocol version should not be HTTPS/1.0 but HTTP/1.0 (without S).

        I corrected it to http in the actual code, it fails with https.

      Thank You Huck that worked now to figure out how to decode streaming JSON.

      Sean