Prev / Next

2003-10-29 / open-uri - very easy to use wrapper to net/http and net/ftp.

openの中に直接URIを書けるようにする。Ruby 1.8標準塔載。

使用例

require 'open-uri'

open("http://www.ruby-lang.org/en/index.html") {|f|
  f.each_line {|line| p line}
  p f.base_uri
  p f.content_type
  p f.charset
  p f.content_encoding
  p f.last_modified
}


open-uri を使わないとこんな感じ

URI.parse("http://www.ruby-lang.org/en/").open(
  "User-Agent" => "Ruby/#{RUBY_VERSION}",
  "From" => "[email protected]",
  "Referer" => "http://www.ruby-lang.org/"
) {|f|
  ...
}


comments powered by Disqus