in reply to Grabbing a web page without LWP or the like
#!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);
}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Grabbing a web page without LWP or the like
by Hot Pastrami (Monk) on Nov 22, 2000 at 02:27 UTC | |
by tye (Sage) on Nov 22, 2000 at 02:44 UTC | |
by Hot Pastrami (Monk) on Nov 22, 2000 at 02:50 UTC | |
by Fastolfe (Vicar) on Nov 22, 2000 at 03:19 UTC | |
by Hot Pastrami (Monk) on Nov 22, 2000 at 03:26 UTC | |
| |
by Hot Pastrami (Monk) on Nov 22, 2000 at 02:44 UTC | |
by merlyn (Sage) on Nov 22, 2000 at 03:46 UTC |