#!c:/perl/bin/perl.exe
# get.pl -- Make an HTTP GET request and report the results
#
# Dave Smith, 6/15/00
use strict;
use IO::Socket;
my $get_or_head = "GET";
my $headeronly = 0;
if ( $ARGV[0] eq "-h" ) {
$headeronly = 1;
$get_or_head = "HEAD";
shift;
}
my $url = shift or usage();
my ($host,$uri) = $url =~ m#^(?:http://|//|)([^/]*)/?(.*)$#;
# print "host=$host uri=$uri\n";
usage() if not $host;
my $sock = IO::Socket::INET->new(PeerAddr => $host,
PeerPort => 'http(80)',
Proto => 'tcp');
die "Couldn't open socket to $host" if not $sock;
print $sock "$get_or_head /$uri HTTP/1.0\r\n",
"Accept: text/plain, text/html, text/xml, image/gif\r\n",
# "If-modified-since: Sat, 14 Jul 2000 01:51:07 GMT\r\n",
"Host: foo.com\r\n",
"\r\n";
while ( <$sock> ) {
s/\r//;
last if $headeronly and /^$/;
print;
}
sub usage {
print <<"END";
usage:
$0 [-h] fully-qualified-URL
-h response header only
END
exit(0);
}
In reply to Re: Grabbing a web page without LWP or the like
by dws
in thread Grabbing a web page without LWP or the like
by Hot Pastrami
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |