user2465510 user2465510 - 5 months ago 43
Ruby Question

How to use Net::HTTP's `get_print` method

I'm trying to create and initialize an instance of

as HTTPClient. When I get to the get_print method, though, it is telling me that it doesn't exist. What am I doing incorrectly?

require 'Net/HTTP'

print "Enter address for HTTP request: "
URL = gets.chomp
puts ''

HTTPClient =, 80)

HTTPClient.get_print URI(URL)


You've stored an instance of the classNet::HTTP in your HTTPClient constant. But get_print isn't an instance method of Net::HTTP (see the docs), it's a singleton method of the class object Net::HTTP itself. Therefore, you cannot call get_print on an instance.

Here's how you might use get_print appropriately:

require 'net/http'

Net::HTTP.get_print('', '/')