-1

I need to open this link with Net::HTTP:

"http://localhost:9292/something"

Terminal:

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

How can I open this link, any idea?

Kurt Russell
  • 225
  • 1
  • 3
  • 15
  • 1
    What are you trying to achieve? Define "open". – Quentin Mar 27 '13 at 10:57
  • 1
    Also, what is wrong with the plethora of examples in [the documentation](http://ruby-doc.org/stdlib-2.0/libdoc/net/http/rdoc/Net/HTTP.html)? – Quentin Mar 27 '13 at 10:58
  • I need to go to this link: "http://localhost:9292/login". With Net::HTTP I can go only to "http://localhost:9292". How can I go to ".../login"? – Kurt Russell Mar 27 '13 at 11:01
  • What do you want to go to the link (obviously **you** can't go. Do you want to fetch the data and put it in a ruby string? Do you want to send the browser there? Something else?) – Quentin Mar 27 '13 at 11:16

1 Answers1

2

You can use open-uri:

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

Or with Net::HTTP:

require 'net/http'
uri = URI('http://localhost:9292/login')
contents = Net::HTTP.get(uri)
Stefan
  • 109,145
  • 14
  • 143
  • 218