End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Net::HTTP.get
get(uri_or_host, path_or_headers = nil, port = nil)
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/net/http.rb, line 474
def HTTP.get(uri_or_host, path_or_headers = nil, port = nil)
get_response(uri_or_host, path_or_headers, port).body
end
Sends a GET request to the target and returns the HTTP response as a string. The target can either be specified as (uri, headers), or as (host, path, port = 80); so:
Example
print Net::HTTP.get(URI('http://www.example.com/index.html'))
or:
Example
print Net::HTTP.get('www.example.com', '/index.html')
you can also specify request headers:
Example
Net::HTTP.get(URI('http://www.example.com/index.html'), { 'Accept' => 'text/html' })