We Recommend

HTML Dog: The Best-Practice Guide to XHTML and CSS HTML Dog: The Best-Practice Guide to XHTML and CSS
For readers who want to design Web pages that load quickly, are easy to update, accessible to all, work on all browsers and can be quickly adapted to different media, this comprehensive guide represents the best way to go about it.


Posted By

cczona on 03/13/08


Tagged

url textmate ruby open read uri open-uri readlines


Versions (?)


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


Published in: Other 


URI objects can be opened directly by open-uri


  1. require "open-uri"
  2.  
  3. uri="http://www.ruby-lang.org/en/"
  4.  
  5. html=URI.parse(uri).read # string representation is the response body
  6.  
  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 

You need to login to post a comment.