conn.get do |req|
req.url '/search'
req.options.timeout = 5 # open/read timeout in seconds
req.options.open_timeout = 2 # connection open timeout in seconds
end
open_timeout[RW]
Number of seconds to wait for the connection to open. Any number may be used, including Floats for fractional seconds. If the HTTP object cannot open a connection in this many seconds, it raises a Net::OpenTimeout exception. The default value is nil.
https://github.com/lostisland/faraday
不需要这么麻烦,使用Net::HTTP就可以了
这个是文档介绍:
顺带翻译一下好了:
另外还有很多其他功能,例如设定代理服务器,CA证书,ssl证书等等。
具体的可以参考文档,这里就不多说了。