From: Mark Hubbart Date: 2005-06-04T15:25:02+09:00 Subject: Re: Help, how to download a binary file through Net::HTTP On 6/3/05, Eric Luo wrote: > Hi, > I'm new to Ruby. I want to download a binary file by Net::HTTP or other > ways. I mimic the > what's been done in the "Programming Ruby". But It failed. I want to know > what the > right way is! The quick way, if you just want the file contents: require 'net/http' data = Net::HTTP.get(URI.parse('http://www.google.com/index.html')) ... data now has the contents of the file. Then there's the slightly more involved way, which lets you reuse the http connection (if you want to fetch more than one file), and get the headers, too: google = Net::HTTP.new('www.google.com', 80) headers, data = google.get 'index.html' Net::HTTP#get (not Net::HTTP.get) returns an array, the first part is the header info, the second is the file data. hth, Mark