require 'socket' require 'uri' def raw_http_request(url, headers = {}, body = nil) uri = URI.parse(url) s = TCPSocket.new(uri.host, uri.port) s.write("GET #{uri.request_uri} HTTP/1.1\r\n") headers.each { |k, v| s.write("#{k}: #{v}\r\n") } s.write("\r\n") s.write(body) if body s.close_write headers, body, found_body = [], "", false s.each_line do |line| if !found_body and line.strip == "" found_body = true next end if found_body body << line else headers << line.strip end end [headers, body] ensure s.close if s end puts raw_http_request("http://localhost:9080/", {"Host" => "localhost:9080", "Content-Length" => 2000}, "Short body")