开发者

open url in ruby controller

开发者 https://www.devze.com 2023-03-03 00:14 出处:网络
I need to call some php script from ROR controller, so I tried to use open(\"url\"), but it didn\'t work.

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 - ht开发者_运维问答tp://stackoverflow.com

Any idea?


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

The API docs


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号