One of the most basic actions you can perform on the Web is downloading a single Web page or document. First we’ll look at how to use the most commonly used Ruby HTTP library, net/http, before moving on to a few notable alternatives.
The net/http Library
The net/http library comes standard with Ruby and is the most commonly used library to access Web sites. Here’s a basic example:

require 'net/http'
url = URI.parse('http://www.rubyinside.com/test.txt')
Net::HTTP.start(url.host, url.port) do |http|
  req = Net::HTTP::Get.new(url.path)
  puts http.request(req).body
end
Advertisements