require 'socket'
hostname='www.ruby-china.org'
#ua='Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11'
header={'User-Agent'=>'curl/7.30.0',
'Host'=>hostname,
'Accept'=>'*/*'
}
req="GET / HTTP/1.1\r\n"
header.each {|key, value| req+= "#{key}: #{value}\r\n" }
req+="\r\n"
port =80
sock = TCPSocket.open(hostname, port)
sock.print req
while line = sock.gets
puts line.chop
end
sock.close