Alex
Alex

Reputation: 13

open url in ruby controller

I need to call some php script from ROR controller, so I tried to use open("url"), but it didn't work.
For example,

def successful_login
  open("http://stackoverflow.com")
  redirect_to home_url
end

Errno::EINVAL in UsersController#create
Invalid argument - http://stackoverflow.com

Any idea?

Upvotes: 0

Views: 3628

Answers (2)

Hitesh
Hitesh

Reputation: 825

require 'net/http' require 'uri'

url = URI.parse('http://www.example.com/index.html')
res = Net::HTTP.start(url.host, url.port) {|http|
  http.get('/index.html')
}
puts res.body

Upvotes: 0

thekindofme
thekindofme

Reputation: 3866

require 'net/http'
Net::HTTP.get('www.example.com', '/index.html')

The API docs

Upvotes: 0

Related Questions