2011-05-03 15 views
0

我需要從ROR控制器調用一些PHP腳本,所以我試圖使用開放(「網址」),但它沒有奏效。
例如,在紅寶石控制器打開網址

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

變量Errno :: EINVAL在UsersController#創建
無效的參數 - http://stackoverflow.com

任何想法?

+0

貌似忘記需要開放-URI:'需要 '開放-URI';打開(的「http: // host /')。閱讀' – taro 2011-05-03 10:06:54

回答

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

The API docs

+0

哦,thx!似乎它更接近解決方案,但我有另一個錯誤(絕對無法識別):Errno :: ECONNRESET(????????? ???? ??????????????? ????????????? ?????????。): – Alex 2011-05-03 09:59:00

+0

打開控制檯/終端並加載irb。然後輸入'require'net/http'。和'Net :: HTTP.get('www.google.com','/ intl/en/about /')'沒有引號。看看它是否給你任何輸出。如果是這樣,它可以正常工作。你想要打什麼網址?你可以用瀏覽器打開它嗎? – thekindofme 2011-05-03 10:06:30

+0

現在,當我打電話給本地主機的網址。儘管事實上,它並不適用於外部URL,但我可以在瀏覽器中打開它。看起來是開發環境問題。非常感謝! – Alex 2011-05-03 10:55:36

0

需要的淨/ HTTP' 需要 '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