如何在 Ruby 中的 RestClient gem 中设置超时?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10483418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set timeout in RestClient gem in Ruby?
提问by sravan_kumar
I am using RestClient gem by making get call to the server through it. The question is how do I set the timeout from client side.
我通过通过它对服务器进行 get 调用来使用 RestClient gem。问题是如何从客户端设置超时。
RestClient.get "http://127.0.0.1:7819/tokenize/word/stackoverflow"
I want to set it to 10 seconds.
我想将其设置为 10 秒。
Thanks in Advance!!
提前致谢!!
回答by Hugo Tavares
You don't need to monkey patch anything. You can use RestClient::Requestdirectly, like:
你不需要猴子修补任何东西。可以RestClient::Request直接使用,比如:
RestClient::Request.execute(:method => :get, :url => url, :timeout => 10, :open_timeout => 10)
But remember the worst case scenario is 20 seconds.
但请记住,最坏的情况是 20 秒。
Check the other post answer https://stackoverflow.com/a/5445421/565999

