Net::HTTP is part of the Ruby standard library. You can use require 'net/http' to download it.
Instead of using Net::HTTP , which is pretty low for what you want to do, I would recommend using Ruby Open::URI .
If you are moving a lot of HTTP data, you may need to look at something like HTTPClient or Curb or Typhoeus, which are designed to be used under difficult conditions and save you from having to write everything using Net::HTTP .
Regarding the ECONNREFUSED error: you might want to grab the HTTPResponse returned from get_response and then check its status before trying to read the body. The way you do it now does not allow you to respond to a failed request.
source share