2012-07-23 105 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]')