#!/share/bin/perl -w use Socket; # Ultra minimal HTTP client, give it hostname, port, and pathname for file # # It doesn't really do a proper request so some server's may throw back # a "400 client request not understood" response # # But it is actually useful as sometimes you want to see things like the # HTTP headers that get sent in a response my ($server,$port, $iaddr, $paddr, $proto, $line); if(@ARGV < 1) { print "Invoke with one or two arguments, hostname and optional port\n"; exit(1); } # Grab command line arguments using shift operations on ARGV vector $server = shift @ARGV; $port = shift @ARGV || 80 ; # without the socket module, this would be quite elaborate code # piecing together the data structure defining the server $iaddr = inet_aton($server) || die "no host: $server"; $paddr = sockaddr_in($port, $iaddr); $proto = getprotobyname('tcp'); socket(SOCK, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect(SOCK, $paddr) || die "connect: $!\n"; # fiddling with autoflush on socket stream select(SOCK); $|=1; select(STDOUT); print "File :"; $input = ; chomp($input); # Write request to socket print SOCK "GET $input HTTP/1.0\n\n"; # hope that get reply, print response line by line while($line = ) { print $line; } close (SOCK) || die "close: $!"; exit;