简体   繁体   English

为什么我不能执行本地Net :: HTTP获取请求?

[英]Why can I not do a local Net::HTTP get request?

So I have a controller action that renders json.. I can visit the url in the browser and see the json data, verifying that the route is working properly... 因此,我有一个呈现json的控制器操作。我可以在浏览器中访问url并查看json数据,从而验证路由是否正常运行...

Yet, if I do: 但是,如果我这样做:

uri = URI("#{request.protocol}#{request.host_with_port}/my_controller/action")
Net::HTTP.get(uri)

I get "Timeout::Error: Timeout::Error" 我收到“超时::错误:超时::错误”

... ? ...?

You're using a single-threaded HTTP server, ie Webrick. 您正在使用单线程HTTP服务器,即Webrick。 This means that it will only be able to serve one request at a time. 这意味着它一次只能处理一个请求。 You're attempting to make a request to the webserver from within the webserver itself. 您正在尝试从Web服务器本身向Web服务器发出请求。 It won't be able to complete this action because of now hopefully obvious reasons. 由于现在希望有显而易见的原因,它将无法完成此操作。

Use a different web server, such as Thin, that would allow for this, or choose a different way to do this. 使用其他Web服务器,例如Thin,可以实现此目的,或选择其他方式来执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM