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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With