I am writing a low-level web client that is having problems connecting to some types of web servers. I find that from some IIS 6.0 web servers and other custom webservers I am unable to receive a response from, and my program returns with no response.
I am able to duplicate the problem with the short script I have created below ( let's call it http.pl ) and I run it like this > ./http.pl www.oracle.com 80
Using 'telnet www.oracle.com 80' and sending HTTP request headers ( GET / HTTP/1.0 ) I can view a response no problem. Why can't the script below do it, and how do I fix this problem?
I would really prefer to use just lower level sockets so I can time the DNS resolution, page response time but more specifically the TCP connection overhead time as this will be part of my display.
Thank you.
use strict;
use IO::Socket;
$|++;
my( $host, $port, $kidpid, $handle, $line );
( $host, $port ) = @ARGV;
my $msg = qq{HEAD / HTTP/1.0\nHOST: $host\n\n};
$handle = IO::Socket::INET->new(
Proto => 'tcp',
PeerAddr => $host,
PeerPort => $port,
Blocking => 0) or die("$!");
$handle->autoflush(1);
$handle->send( $msg, undef, "test" );
my @results;
for( 0..10 ) {
last if @results = $handle->getlines;
select(undef, undef, undef, .5);
}
print @results;
exit;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.