Net :: HTTP请求连接太慢了?

时间:2015-10-02 07:52:28

标签: ruby http ovh

我已经从ovh-rest gem中提取了以下代码:

method = :get
@api_url = "https://api.ovh.com/1.0"
@api_key, @api_secret, @consumer_key = "123456789", "abcdef", "ghijkl"
endpoint = "/ip/123.456.678/"
url = @api_url + endpoint
uri = URI.parse(url)
body = nil
ts = Time.now.to_i.to_s
sig = "$1$" + Digest::SHA1.hexdigest("#{@api_secret}+#{@consumer_key}+#{method.upcase}+#{url}+#{body}+#{ts}")
request_uri = uri.path
request_uri += '?' + uri.query if uri.query
request = Net::HTTP.const_get(method.capitalize).new(request_uri)
request["X-Ovh-Application"] = @api_key
request["X-Ovh-Consumer"] = @consumer_key
request["X-Ovh-Timestamp"] = ts
request["X-Ovh-Signature"] = sig
request["Content-type"] = "application/json"
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
response = http.request(request)
JSON.parse(response.body)

如果我一步一步地做所有事情,我会发现以下错误:

{
  "errorCode": "QUERY_TIME_OUT",
  "httpCode": "400 Bad Request",
  "message": "Query out of time"
} 

但如果我在做response = http.request(request)之前等待几秒钟(可变持续时间),我就会成功请求:

{
  "organisationId": "nil",
  "country": "myCountry",
  "routedTo": {
    "serviceName": "somename"
  },
  "ip": "123.456.678/32",
  "canBeTerminated": true,
  "type": "failover",
  "description": "nil"
}

我不知道问题是来自我的服务器(ruby进程到高速以便快速响应),还是来自其他地方......

重要提示:

这段代码的工作就像一个魅力,但几天前..停止工作。

1 个答案:

答案 0 :(得分:0)

这是由日期resynchro解决的。由于所有服务器的工作时间都相同,因此它就像一个魅力。