Ruby/Network/net http library
Материал из Wiki.crossplatform.ru
(Различия между версиями)
Версия 17:10, 26 мая 2010
Get body of response
require "net/http" url = URI.parse("http://www.rubyinside.ru/test.txt") response = Net::HTTP.get_response(url) puts response.body
The net/http Library
require "net/http" Net::HTTP.start("http://www.rubyinside.ru/") do |http| req = Net::HTTP::Get.new("/test.txt") puts http.request(req).body end
turn a URL into the various pieces needed by net/http.
require "net/http" url = URI.parse("http://www.rubyinside.ru/test.txt") Net::HTTP.start(url.host, url.port) do |http| req = Net::HTTP::Get.new(url.path) puts http.request(req).body end