2012-07-23 44 views
0

我想從一個Rails應用程序發送一個POST/GET到一個特定的地址。然而,當我運行應用程序,我得到了錯誤:「無連接可以作出,因爲目標機器積極地拒絕它 - (2)連接。」下面是我的代碼:Rails - 由於目標機器主動拒絕,無法建立連接。 - connect(2)

def show 
    @uri = URI('example.com/getuser?user=bob&[email protected]') 
    @profile = Net::HTTP.get(@uri) 
    puts @profile 
    end 
+0

你確定你想查詢服務器啓動並運行? – Strelok 2012-07-23 15:50:10

+0

是的。嘗試在interner瀏覽器中粘貼url並且它工作正常。 – user1480797 2012-07-23 15:51:53

+2

試試這個:'@uri = URI('http://example.com/getuser?user=bob&[email protected]')' – 2012-07-23 15:52:40

回答

0

我這個標記作爲答覆,以便使未來可能來到這裏的人更具可讀性。這首先在評論中回覆。

問題是URI不是以HTTP爲中心的。所以協議需要被指定。

以下工作:

@uri = URI('http://example.com/getuser?user=bob&[email protected]') 
相關問題