Ruby uniquest请求:错误500

时间:2017-06-21 07:57:16

标签: ruby http httprequest http-status-code-500 unirest

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

所以我创建了2个数组,一个用于请求标头,另一个用于请求主体,但它似乎不起作用。

# 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

返回错误代码500,答案标题和空体:

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进行简单的帖子请求,效果很好:Hurl.it request

1 个答案:

答案 0 :(得分:-1)

最后找到解决方案,脚本在这里是不可取的:https://github.com/bastienrobert/Sellsy-API