首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在rails中使用httparty的get请求中区分大小写的标头

在rails中使用httparty的get请求中区分大小写的标头
EN

Stack Overflow用户
提问于 2018-07-13 02:15:10
回答 2查看 1.1K关注 0票数 1

当我使用httparty发出GET请求时,我当前收到了一个错误。当我使用curl时,调用可以正常工作。错误如下:

\"Authdate\":\"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

有什么解决方法吗?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51312102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档