Ruby on rails Rails-无法建立连接,因为目标计算机主动拒绝了它。-连接(2)

Ruby on rails Rails-无法建立连接,因为目标计算机主动拒绝了它。-连接(2),ruby-on-rails,http,url,connection,uri,Ruby On Rails,Http,Url,Connection,Uri,我想从Rails应用程序向特定地址发送POST/GET。然而,当我运行应用程序时,我得到了一个错误:“无法建立连接,因为目标计算机主动拒绝了它。-connect(2)”下面是我的代码: def show @uri = URI('example.com/getuser?user=bob&email=bob84@gmail.com') @profile = Net::HTTP.get(@uri) puts @profile end 我将此标记为一个回复,以便

我想从Rails应用程序向特定地址发送POST/GET。然而,当我运行应用程序时,我得到了一个错误:“无法建立连接,因为目标计算机主动拒绝了它。-connect(2)”下面是我的代码:

  def show
    @uri = URI('example.com/getuser?user=bob&email=bob84@gmail.com')
    @profile = Net::HTTP.get(@uri)
    puts @profile
  end

我将此标记为一个回复,以便将来可能来到这里的人更容易阅读。这首先在评论中得到答复

问题在于
URI
不是以HTTP为中心的。因此,需要指定协议

以下工作:

 @uri = URI('http://example.com/getuser?user=bob&email=bob84@gmail.com')

您确定要查询的服务器已启动并正在运行吗?是的。尝试在interner浏览器中粘贴url,效果良好。请尝试以下操作:
@uri=uri('http://example.com/getuser?user=bob&email=bob84@好吧,我刚刚意识到这是个愚蠢的错误。。哈哈,把“http://”放在前面肯定有用!非常感谢!:)