/ Published in: Other
URI objects can be opened directly by open-uri
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
require "open-uri" uri="http://www.ruby-lang.org/en/" html=URI.parse(uri).read # string representation is the response body http_headers=URI.parse(uri).read.meta # this hash's keys are also accessible as OpenURI instance methods, e.g. html.content_type