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.