Request method (GET, TRACE, OPTIONS, or HEAD - HEAD is default)? h Enter host: www.perlmonks.org Port (80 is default)? Path (/index.html is default)? Attempting to connect to www.perlmonks.org:80 HEAD /index.html HTTP/1.1 Host: www.perlmonks.org HTTP/1.1 200 OK Date: Sun, 26 Nov 2000 21:17:19 GMT Server: Apache/1.3.9 (Unix) mod_perl/1.21 Last-Modified: Fri, 17 Nov 2000 02:57:44 GMT ETag: "23e95c-0-3a149ea8" Accept-Ranges: bytes Content-Length: 0 Connection: close Content-Type: text/html X-Pad: avoid browser bug
#!/usr/bin/perl -w use strict; use IO::Socket; my %method = ( g => 'GET', h => 'HEAD', o => 'OPTIONS', t => 'TRACE' ); my $method = ''; while ( $method !~ /^[gtho]/i ) { print 'Request method (GET, TRACE, OPTIONS, or HEAD - HEAD is defa +ult)? '; $method = <STDIN>; $method = 'HEAD' if ! $method; } $method = $method{ lc substr $method, 0, 1 }; my $host = ''; while ( ! $host ) { print 'Enter host: '; chomp ( $host = <STDIN> ); } my $port = 0; while ( $port < 1 or $port > 65535 ) { print 'Port (80 is default)? '; chomp ( $port = <STDIN> ); $port = 80 if ! $port; } my $path = ''; while ( ! $path ) { print 'Path (', $method eq 'OPTIONS' ? '*' : '/index.html', ' is + default)? '; chomp ( $path = <STDIN> ); if ( ! $path ) { $path = ( $method eq 'OPTIONS' ) ? '*' : '/index.html'; } } my $maxForwards = 0; if ( $method eq 'TRACE' ) { while ( $maxForwards < 1 ) { print 'Max forwards? '; chomp ( $maxForwards = <STDIN> ); } } print "Attempting to connect to $host:$port\n"; my $target = new IO::Socket::INET("$host:$port"); my $request = "$method $path HTTP/1.1\n" . "Host: $host\n"; $request .= "Max-Forwards: $maxForwards\n" if $method eq 'TRACE'; $request .= "\n"; print "\n$request"; # Send the headers to the host print $target $request; my $response; { undef $/; # Here are the headers $response = <$target>; } print $response;
In reply to Learning HTTP headers by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |