Skip to content

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

get(uri_or_host, path_or_headers = nil, port = nil)

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' })
See also #get .default_port .get_print .get_response also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1