Programming Tutorials

(追記) (追記ここまで)

Reading URL content using Ruby (HTTP)

By: Emiley J. in Ruby Tutorials on 2009年03月03日 [フレーム]

Example 1: Simple GET+print

 require 'net/http'
 Net::HTTP.get_print 'www.example.com', '/index.html'

Example 2: Simple GET+print by URL

 require 'net/http'
 require 'uri'
 Net::HTTP.get_print URI.parse('http://www.example.com/index.html')

Example 3: More generic GET+print

 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

Example 4: More generic GET+print

 require 'net/http'
 url = URI.parse('http://www.example.com/index.html')
 req = Net::HTTP::Get.new(url.path)
 res = Net::HTTP.start(url.host, url.port) {|http|
 http.request(req)
 }
 puts res.body



(追記) (追記ここまで)


Add Comment

JavaScript must be enabled for certain features to work
* Required information
1000

Comments

No comments yet. Be the first!
(追記) (追記ここまで)
(追記) (追記ここまで)

AltStyle によって変換されたページ (->オリジナル) /