Ruby/Network/Proxy

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Get response for HTTP requests,

require "net/http"
web_proxy = Net::HTTP::Proxy("your.proxy.hostname.or.ip", 8080)
url = URI.parse("http://www.rubyinside.ru/test.txt")
response = web_proxy.get_response(url)
puts response.body



web_proxy replaces the reference to Net::HTTP when using the start method.

require "net/http"
web_proxy = Net::HTTP::Proxy("your.proxy.hostname.or.ip", 8080)
url = URI.parse("http://www.rubyinside.ru/test.txt")
web_proxy.start(url.host, url.port) do |http|
  req = Net::HTTP::Get.new(url.path)
  puts http.request(req).body
end