parse URI object, and fetch response from it, in one step

/ Published in: Other
Save to your folder(s)

URI objects can be opened directly by open-uri

Copy this code and paste it in your HTML
  1. require "open-uri"
  3. uri=""
  5. html=URI.parse(uri).read # string representation is the response body
  7. http_headers=URI.parse(uri).read.meta # this hash's keys are also accessible as OpenURI instance methods, e.g. html.content_type

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.