所以我正在调用一个保持超时的 API,即使我将超时设置为 1000 秒,它在 30 秒后超时,我的实现可能是错误的。
require 'HTTParty'
require 'json'
class Api
include HTTParty
default_timeout 1000
@@Json
def initialize(api_root_url, code)
response = HTTParty.get("#{api_root_url}/api/page/"+code)
@@Json = JSON.parse(response.body)
end
end
错误
/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:146:in rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:140:in
rbuf_fill' 来自 .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1 /net/protocol.rb:122:in readuntil'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/protocol.rb:132:in
readline' 来自 .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2562:in read_status_line'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:2551:in
read_new' 来自 .rbenv/versions/1.9 .3-p194/lib/ruby/1.9.1/net/http.rb:1319:in block in transport_request'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1316:in
catch' 来自 .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb: 1316:in transport_request'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1293:in
request' from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1286:in block in request'
from .rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/net/http.rb:745:in
start' from .rbenv/versions/1.9.3-p194/lib/ ruby/1.9.1/net/http.rb:1284:in `request'
提前致谢