Net :: HTTP - 如何打开带地址的链接?

时间:2013-03-27 10:53:58

标签: ruby-on-rails-3 faye net-http

我需要使用Net :: HTTP打开此链接:

"http://localhost:9292/something"

终端:

http = Net::HTTP.new("http://localhost",9292)
=> #<Net::HTTP http://localhost:9292 open=false>

我怎么能打开这个链接,任何想法?

1 个答案:

答案 0 :(得分:2)

您可以使用open-uri

require 'open-uri'
contents = open('http://localhost:9292/login') {|f| f.read }

Net::HTTP

require 'net/http'
uri = URI('http://localhost:9292/login')
contents = Net::HTTP.get(uri)