RestClient帖子获取RestClient :: BadRequest(400错误请求)

时间:2019-10-15 20:12:08

标签: ruby-on-rails rest-client plaid

我已经在这里进行了挖掘,找不到有效的可接受答案。我正在使用rest-client gem向Plaid API发出发布请求。我已经在邮递员中处理了该请求,但无法使其与rest-client一起工作。

这是我的代码(标记是经过编辑的)

  url = 'https://sandbox.plaid.com/transactions/get'
    payload = {client_id: '################',
               secret: '######################',
               access_token: ###############,
               start_date: '2019-01-01',
               end_date: '2019-01-31',
              options: {count: 250, offset: 100}}.to_json
    header = {content_type: 'application/json'}
    response = RestClient.post(url, payload, header)

这是邮递员的请求(它的NET:Http是因为所有邮递员都提供了

require 'uri'
require 'net/http'

url = URI("https://sandbox.plaid.com/transactions/get")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request["User-Agent"] = 'PostmanRuntime/7.18.0'
request["Accept"] = '*/*'
request["Cache-Control"] = 'no-cache'
request["Postman-Token"] = 'c06e3d95-5f18-489f-b3b6-0dfb554ee09f,00fdadfc-9986-48ff-9052-6ff3883a0dfb'
request["Host"] = 'sandbox.plaid.com'
request["Accept-Encoding"] = 'gzip, deflate'
request["Content-Length"] = '300'
request["Connection"] = 'keep-alive'
request["cache-control"] = 'no-cache'
request.body = "{\n    \"client_id\": \"5d923beaa466f10012dc1363\",\n    \"secret\": \"39395b2e8800dadd85947f7fad7bee\",\n    \"access_token\": \"access-sandbox-e1ab5ece-a4b9-4d13-b254-53bf1473c01d\",\n    \"start_date\": \"2019-01-01\",\n    \"end_date\": \"2019-12-01\",\n    \"options\": {\n        \"count\": 250,\n        \"offset\": 100\n    }\n}"

response = http.request(request)
puts response.read_body

0 个答案:

没有答案