0

我在 myapp.heroku.com 上构建了一个网络应用程序,其中“myapp”实际上是 heroku 生成的随机名称。当我用我的网络浏览器点击它时,它就可以工作了。当我使用 Ruby Rest-Client (gem rest-client v1.6.3) 按如下方式点击它时:

irb(main):024:0> response=RestClient.get "http://myapp.heroku.com"

它与以下内容有关:

RestClient::InternalServerError: 500 Internal Server Error
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-    1.6.3/lib/restclient/abstract_response.rb:48:in `return!'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:228:in `process_result'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:176:in `block in transmit'
    from C:/Ruby192/lib/ruby/1.9.1/net/http.rb:627:in `start'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:170:in `transmit'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:64:in `execute'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient/request.rb:33:in `execute'
    from C:/Ruby192/lib/ruby/gems/1.9.1/gems/rest-client-1.6.3/lib/restclient.rb:68:in `get'
    from (irb):24
    from C:/Ruby192/bin/irb:12:in `<main>'

当我使用具有更知名的 URL(例如“http://www.google.com”或“http://www.heroku.com”)的同一客户端时,它可以正常工作,URL 的内容会下载,并且一切都是好的。当我将同一个客户端与在“http://localhost:3000”上运行的应用程序版本一起使用时,它也可以正常工作。

我是否在我的 rest-client 客户端中遗漏了一些东西,阻止它从 heroku.com 上托管的应用程序获取数据?

============ 编辑 ==== 附加信息 ===========

在上面睡觉后,我尝试了:

irb> require 'net/http'
irb> NET::HTTP.get_print URI.parse "http://myapp.heroku.com"

它工作得很好。

4

2 回答 2

0

这里可能有很多原因;

如果您使用的是单个测功机,它会发出请求,但随后会返回站点,但没有可用于处理请求的测功机,因此会超时。

在某些情况下,服务器无法在其外部地址上与其自身对话,但我认为这不太可能,更可能是测功机问题?

约翰。

于 2011-08-10T08:13:21.687 回答
0

我搞砸了。

检查“heroku 日志”后,我发现我的代码中有一个异常,导致 500 错误。例外是因为 heroku 中的 PG 数据库和我的本地 SQLite3 数据库之间的类型转换差异。一旦我修好了,一切都很顺利。我怀疑 500 错误也导致我的网站暂时无法访问,这就是为什么我的网站所在的子域没有返回任何内容。

Moral of the story? rest-client works. Heroku works. Rest-client (IMO) shouldn't throw exceptions for a 500, but just return the HTTP response code and let the app deal with it. However, if I whine more, I'll also have to fork & fix...

于 2011-08-10T16:35:03.677 回答