【问题标题】:Rails - No connection could be made because the target machine actively refused it. - connect(2)Rails - 无法建立连接,因为目标机器主动拒绝了它。 - 连接(2)
【发布时间】:2012-07-23 15:47:27
【问题描述】:

我想从 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 = URI('http://example.com/getuser?user=bob&email=bob84@gmail.com')
  • 好吧,我刚刚意识到这是一个愚蠢的错误。哈哈,把'http://'放在前面绝对有效!非常感谢! :)

标签: ruby-on-rails http url connection uri


【解决方案1】:

我将此标记为回复,以便将来可能来到这里的人更容易阅读。这是第一次在 cmets 中回复。

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

以下作品:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-24
    • 2023-03-25
    • 1970-01-01
    • 2015-04-05
    • 2016-12-08
    • 2014-09-05
    • 2017-06-01
    相关资源
    最近更新 更多