my $host = 'localhost';
my $path = '/cgi-bin/second.pl';
my $port = 80;
####
my $CONN = IO::Socket::INET->new("$host:$port")
or die "Couldn't connect: $!";
####
my $req = "GET $path HTTP/1.0 $CRLF$CRLF";
$CONN->syswrite($req);
####
$/ = CRLF . CRLF; #To read the whole header as one 'line'
binmode $CONN; #Turn off \n conversion for getline() in next line
my $header = $CONN->getline;
$header =~ s/$CRLF/\n/g;
say $header;
--output:--
HTTP/1.1 200 OK
Date: Sun, 21 Feb 2010 12:28:24 GMT
Server: Apache/2.2.4 (Unix) mod_ssl/2.2.4 OpenSSL/0.9.7l DAV/2 PHP/5.2.3 mod_python/3.3.1 Python/2.4.4
Content-Length: 294
Connection: close
Content-Type: text/html
####
my $CONN = IO::Socket::INET->new(
Peerhost => $host,
Peerport => 'http(80)',
) or die "Couldn't connect: $!";
####
Use of uninitialized value $header in substitution (s///) at 4perl.pl line 55.
Use of uninitialized value $header in say at 4perl.pl line 56.
####
use strict;
use warnings;
use 5.010;
use IO::Socket qw{ :DEFAULT :crlf };
my $host = 'localhost';
my $path = '/cgi-bin/second.pl';
my $port = 80;
=pod
my $CONN = IO::Socket::INET->new("$host:$port")
or die "Couldn't connect: $!";
=cut
my $CONN = IO::Socket::INET->new(
Peerhost => $host,
Peerport => 'http(80)',
) or die "Couldn't connect: $!";
my $req = "GET $path HTTP/1.0 $CRLF$CRLF";
$CONN->syswrite($req);
$/ = CRLF . CRLF; #To read whole header as one 'line'
binmode $CONN; #turn off \n conversion for getline() below
my $header = $CONN->getline;
$header =~ s/$CRLF/\n/g;
say $header;
$CONN->close;