Method: Net::HTTP.get_response

Defined in:
lib/net/http.rb

.get_response(uri_or_host, path = nil, port = nil, &block) ⇒ Object

Send a GET request to the target and return the response as a Net::HTTPResponse object. The target can either be specified as (uri), or as (host, path, port = 80); so:

res = Net::HTTP.get_response(URI.parse('http://www.example.com/index.html'))
print res.body

or:

res = Net::HTTP.get_response('www.example.com', '/index.html')
print res.body


371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/net/http.rb', line 371

def HTTP.get_response(uri_or_host, path = nil, port = nil, &block)
  if path
    host = uri_or_host
    new(host, port || HTTP.default_port).start {|http|
      return http.request_get(path, &block)
    }
  else
    uri = uri_or_host
    new(uri.host, uri.port).start {|http|
      return http.request_get(uri.request_uri, &block)
    }
  end
end