Net::HTTPResponse's body is a stream-like object, and you get can read its input in lazy chucks using read_body. In the rest of ruby, steams are represented as class IO. Is there a wrapper or something that lets me use a Net::HTTPResponse as if it was an IO object?
+1
A:
Use the OpenURI library that comes with standard Ruby. It uses Net::Http under the hood, and provides a convenient File-like object.
require 'open-uri'
open('http://example.com/some_file') do |f|
f.each_line do |line|
puts "http line: #{line}"
end
do
Kevin
2010-03-26 19:19:24