DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Fetch A URL In Ruby
require 'uri' require 'net/http' url = "http://www.whatever.com/whatever.txt" r = Net::HTTP.get_response(URI.parse(url).host, URI.parse(url).path)
r.code = 200 | 404 | 500, etc r.body = *text of page*






Comments
Anonymous ˙ˆ∆∂ˆßå replied on Thu, 2006/09/14 - 11:14pm
require 'open-uri' puts open("http://jicksta.com").readSnippets Manager replied on Mon, 2012/05/07 - 2:13pm
get_response, of course.Snippets Manager replied on Mon, 2012/05/07 - 2:13pm
r = Net::HTTP.get_reponse( URI.parse( url ) )rather than parse twice and pull out the important bits.