in reply to read aka fread(3) broken, sysread aka read(2) works IIS socket

On a related noted (related by code, not by problem): Using HTTP/1.0 will prevent your code from working against a virtually hosted site. (Virtual hosting allows multiple domains to share an IP address. Making that work requires passing a domain name in the HTTP request.) Switching to HTTP/1.1 should be very, very easy. Try changing
print $sock "GET $url HTTP/1.0 Host: localhost
to
print $sock "GET $url HTTP/1.1 Host: $host
That should do it.

Replies are listed 'Best First'.
Re: Re: read aka fread(3) broken, sysread aka read(2) works IIS socket
by iburrell (Chaplain) on Sep 11, 2003 at 19:50 UTC
    Using the "Host:" header with HTTP/1.0 is acceptable. Web servers that supports virtual hosts almost always support it. Ancient web servers that don't support virtual hosts will usually just ignore the header. It is safest to always include the "Host" header with HTTP/1.0 requests.

    More importantly, the HTTP/1.1 protocol has requirements for clients that manual scripts aren't willing to do. For example, HTTP/1.1 clients must support chunked encoding. And handle persistent connections gracefully. Clients don't want a persistent connection should send "Connection: close" header.