Rails 实现页面的基本认证 (Basic Authentication)

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

require 'net/http'

url = URI.parse('http://www.rubyinside.com/test.txt')

Net::HTTP.start(url.host, url.port) do |http|
  req = Net::HTTP::Get.new(url.path)
  req.basic_auth('username', 'password')
  puts http.request(req).body
end