【发布时间】:2018-12-21 01:35:28
【问题描述】:
我目前在使用 httparty 发出 GET 请求时遇到错误。当我使用curl 时,通话有效。错误如下:
\"验证日期\":\"1531403501\"}" }, { "error_code": "external_auth_error", "error_message": "日期标头丢失或 时间戳越界" } ] }
当我通过curl 发出请求时,这是我使用的标头。
curl -X GET -H "AuthDate: 1531403501"
但是,如您所见,请求从 AuthDate 更改为 Authdate 导致错误。这是我打电话的方式:
require 'openssl'
require 'base64'
module SeamlessGov
class Form
include HTTParty
attr_accessor :form_id
base_uri "https://nycopp.seamlessdocs.com/api"
def initialize(id)
@api_key = ENV['SEAMLESS_GOV_API_KEY']
@signature = generate_signature
@form_id = id
@timestamp = Time.now.to_i
end
def relative_uri
"/form/#{@form_id}/elements"
end
def create_form
self.class.get(relative_uri, headers: generate_headers)
end
private
def generate_signature
OpenSSL::HMAC.hexdigest('sha256', ENV['SEAMLESS_GOV_SECRET'], "GET+#{relative_uri}+#{@timestamp}")
end
def generate_headers
{
"Authorization" => "HMAC-SHA256 api_key='#{@api_key}' signature='#{@signature}'",
"AuthDate" => @timestamp
}
end
end
end
有什么解决方法吗?
【问题讨论】:
标签: ruby ruby-on-rails-5 httparty net-http