Method: Net::HTTP.get_response
- Defined in:
- lib/extensions/net-http/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
397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/extensions/net-http/net/http.rb', line 397 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 |