> -----Original Message----- > From: Octavian Rasnita [mailto:[EMAIL PROTECTED]] > Sent: Thursday, October 03, 2002 6:58 AM > To: [EMAIL PROTECTED] > Subject: I've solved a problem. But why? > > > Hi all, > > I've tried to make a script that gets a remote html page > using IO::Socket. > If I wanted to use (like in some example from books) GET > $path HTTP/1.1, > the script didn't want to work. > But it works OK if I ask for HTTP/1.0.
HTTP 1.1 requires a Host request header. See sec. 14.3 of RFC 2616. http://www.w3.org/Protocols/rfc2616/rfc2616.txt Also, persistent connections are the default. See sec. 8.1. Use LWP. Don't reinvent the wheel. > > The strange thing is that the header returned by the Apache > Server running > in Windows 2k says that it is HTTP/1.1, even though I've > asked for HTTP/1.0. > > Of course, this is happening only if I rename the file as index.html. > If I let it as index.shtml, it doesn't work with any method. > It prints only the first 4 KB of the html file. That sounds like a server-side problem. > > Can you tell me why is not working if I try with HTTP/1.1, > and why is not > working with .shtml files? > > Thanks. > > Here is the script: > > #!/perl/bin/perl -w > > print "Content-type: text/html\n\n"; > > use IO::Socket; > > my $host = "127.0.0.1"; > my $path = "/test.html"; > my $port = 80; > > my $socket = IO::Socket::INET -> new(PeerAddr => $host, > PeerPort => $port, > Proto => 'tcp', > Type => SOCK_STREAM, > Timeout => 5, > ) > > or die "Cannot connect to the server.\n"; > > $socket->autoflush(1); > > #print $socket "GET $path HTTP/1.0\n", > #"Host: $host\n\n"; > > print $socket "GET /index.shtml\n\n"; > > my $sock = <$socket>; > > while (<$socket>) { > print; > } > > $socket->close; > > Teddy's Center: http://teddy.fcc.ro/ > Mail: [EMAIL PROTECTED] > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]