End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Net::HTTP.get_response
get_response(uri_or_host, path_or_headers = nil, port = nil, &block)
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/lib/net/http.rb, line 486
def HTTP.get_response(uri_or_host, path_or_headers = nil, port = nil, &block)
if path_or_headers && !path_or_headers.is_a?(Hash)
host = uri_or_host
path = path_or_headers
new(host, port || HTTP.default_port).start {|http|
return http.request_get(path, &block)
}
else
uri = uri_or_host
headers = path_or_headers
start(uri.hostname, uri.port,
:use_ssl => uri.scheme == 'https') {|http|
return http.request_get(uri, headers, &block)
}
end
end
Sends a GET request to the target and returns the HTTP response as a Net::HTTPResponse object. The target can either be specified as (uri, headers), or as (host, path, port = 80); so:
Example
res = Net::HTTP.get_response(URI('http://www.example.com/index.html')) print res.body
or:
Example
res = Net::HTTP.get_response('www.example.com', '/index.html') print res.body
you can also specify request headers:
Example
Net::HTTP.get_response(URI('http://www.example.com/index.html'), { 'Accept' => 'text/html' })
See also
.get_print
.http_default_port
.get
.https_default_port
also in
4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1