#!/usr/bin/perl -w

use IO::Socket;
unless (@ARGV > 1) { die "usage: $0 host document ..." }
$host = shift(@ARGV);
$document = shift(@ARGV);

$EOL = "\015\012";

# socket & connect
$remote = IO::Socket::INET->new( Proto     => "tcp",
								 PeerAddr  => $host,
								 PeerPort  => 80,
							   );
unless ($remote) { die "cannot connect to http daemon on $host" }
$remote->autoflush(1);

print $remote "GET /$document HTTP/1.0" . $EOL x 2;

# if you specify whole URL at command line, then beginning /
# is not needed. Apache seems to require full URL
# Use, e.g. perl webget16.pl cs.joensuu.fi http://cs.joensuu.fi/index.html
#print $remote "GET $document HTTP/1.0" . $EOL x 2;

while ( <$remote> ) {
	print;
}

close $remote;

