Ruby 唯一请求:错误 500

Ruby uniquest request : error 500

当我尝试执行这个最独特的 Ruby 脚本时,只收到 HTTP 错误 500。目标是在使用 oauth 进行身份验证的 API 上发出 HTTP POST 请求。

所以我制作了 2 个数组,一个用于请求 header,第二个用于请求 body,但它似乎不起作用。

# Import unirest & yaml (for debugging)
require 'unirest'
require 'yaml'

# Generate Timestamp for oauth authenticate
@timestamp = Time.now.to_i

# Head array
@toHead = {
  "Cache-Control" => "no-cache",
  "Accept" => "*/*",
  "Accept-Encoding" => "gzip, deflate",
  "Content-Type" => "application/x-www-form-urlencoded",
  "User-Agent" => "runscope/0.1",
  "Content-Length" => "94",
  "Authorization" => {
    "oauth_nonce" => '12345678',
    "oauth_timestamp" => "#{@timestamp}",
    "oauth_version" => '1.0',
    "oauth_signature_method" => 'PLAINTEXT',
    "oauth_consumer_key" => 'CONSUMER_KEY',
    "oauth_token" => 'TOKEN_KEY',
    "oauth_signature" => "CONSUMER_SECRET&TOKEN_SECRET"
  }
}

# Body array
@toSend = {
  :io_mode => "json",
  :request => 1,
  :do_in => {
    :method => 'Client.getList',
    :params => []
  }
}

# Launch the request
response = Unirest.post "https://apifeed.sellsy.com/0/",
                        headers:@toHead,
                        parameters:@toSend

# Get the response
response.code
response.headers
response.body
response.raw_body

那个 returns 一个错误代码 500,答案 headers 和一个空的 body :

code: 500
headers:
  :server: nginx
  :date: Wed, 21 Jun 2017 07:43:03 GMT
  :content_type: application/json; encoding=utf-8
  :content_length: '0'
  :connection: keep-alive
  :keep_alive: timeout=10
raw_body: ''
body: ''

编辑:我尝试使用 hurl.it 进行简单的 post 请求,效果很好:

终于找到解决办法了,脚本在这里不负责任:https://github.com/bastienrobert/Sellsy-API