Get file over web

Hi! I'm looking for a function to get the contents from a file on the
web into a string. Something like in PHP: $string =
file_get_contents("http://php.net");

···

--
Posted via http://www.ruby-forum.com/.

require 'net/http'
     require 'uri'

     url = URI.parse('http://www.example.com/index.html'\)
     res = Net::HTTP.start(url.host, url.port) {|http|
       http.get('/index.html')
     }
     puts res.body

The HTTP get is put into the 'res' variable. 'res.body' is the String.

See the documentation for Net::HTTP at RDoc Documentation

cr

···

On Jun 12, 2006, at 2:22 PM, Magnus Holm wrote:

Hi! I'm looking for a function to get the contents from a file on the
web into a string. Something like in PHP: $string =
file_get_contents("http://php.net");

Check out open-uri:
http://ruby.outertrack.com/file/ruby-1.8.4%2Flib%2Fopen-uri.rb
This is one possibility:

  uri = URI.parse("http://php.net")
  string = uri.read

Alex

···

On Monday 12 June 2006 20:22, Magnus Holm wrote:

Hi! I'm looking for a function to get the contents from a file on the
web into a string. Something like in PHP: $string =
file_get_contents("http://php.net");