Ruby 连接到 TCP 服务器并读取回应

require 'net/telnet'

server = Net::Telnet::new('Host' => 'http://www.rubyinside.com/',
                          'Port' => 80,
                          'Telnetmode' => false)

server.cmd("GET / HTTP/1.1\nHost: http://www.rubyinside.com/\n") do |response|
  puts response
end

编程技巧