简体   繁体   中英

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...

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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