Brian Candler wrote:
> On Sun, Apr 08, 2007 at 05:28:07AM +0900, Hey You wrote:
>> Well I don't know why the socket can't connect to Google. Here is my
>> source code:
>> 
>> require 'socket'
>> h = TCPSocket.new('www.google.ca',80)
>> h.print "GET /index.html HTTP/1.0\n\n"
>> a = h.read
>> puts a
>> 
>> I tried changing the HTTP to 1.1 but it still doesn't work.
> 
> Two problems:
> (1) Line terminator for HTTP is \r\n not \n
> (2) You have not supplied a Host: header
> 
> h.print "GET /index.html HTTP/1.0\r\nHost: www.google.ca\r\n\r\n"
> 
> I say again: you must read and understand RFC 2616.
> 
> This documents HTTP/1.1, which has gained a lot of features. You could 
> try
> reading the earlier RFCs for HTTP/1.0 or HTTP/0.9 for a simplified 
> protocol.
> 
> B.

Have you read what I last posted? Or did you just ignore it and gave me 
the answer to a already answered question? Yes I have read RFC2616 more 
than once and I do understand a lot of it but not all stays on my head 
in the few times I read the document. I don't know but I have read in a 
lot of places that for a line terminator you can also use "\n\n" and it 
seems to work fine. Also putting the Host header or adding the full 
domain to the code such as "GET www.google.ca/index.html" both specifies 
which host we want so I don't see why change them.

-- 
Posted via http://www.ruby-forum.com/.