Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何将CURL请求转换为Ruby-Gem-HTTPClient_Ruby On Rails_Ruby_Curl_Rest Client - Fatal编程技术网

Ruby on rails 如何将CURL请求转换为Ruby-Gem-HTTPClient

Ruby on rails 如何将CURL请求转换为Ruby-Gem-HTTPClient,ruby-on-rails,ruby,curl,rest-client,Ruby On Rails,Ruby,Curl,Rest Client,我正在尝试转换此卷曲请求: curl \ -F 'slideshow_spec={ "images_urls": [ "<IMAGE_URL_1>", "<IMAGE_URL_2>", "<IMAGE_URL_3>" ], "duration_ms": 2000, "transition_ms": 200 }' \ -F 'access_token=<ACCE

我正在尝试转换此卷曲请求:

curl \
  -F 'slideshow_spec={ 
    "images_urls": [ 
      "<IMAGE_URL_1>", 
      "<IMAGE_URL_2>", 
      "<IMAGE_URL_3>" 
    ], 
    "duration_ms": 2000, 
    "transition_ms": 200 
  }' \
  -F 'access_token=<ACCESS_TOKEN>' \
  https://google.com

有什么想法吗?

你的要求不一样。我猜您在这里混合了
JSON
Multipart
x-www-form-urlencoded
格式

RestClient支持所有三种格式(示例取自)

看起来您的curl示例使用的是
application/x-www-form-urlencoded
,而Ruby示例使用的是
multipart/form-data

有关一些背景信息,请查看

  payload = {
        "images_urls": [
          "https://cdn-m2.esoftsystems.com/10100028/TAASTRUP%40DANBOLIG.DK/10106239925/160596797/BEST_FIT/1542/1024/IMG_5511.jpg",
          "https://cdn-m2.esoftsystems.com/10100028/TAASTRUP%40DANBOLIG.DK/10106239925/160596797/BEST_FIT/1542/1024/IMG_5511.jpg",
          "https://cdn-m2.esoftsystems.com/10100028/TAASTRUP%40DANBOLIG.DK/10106239925/160596797/BEST_FIT/1542/1024/IMG_5511.jpg"
        ],
        "duration_ms": 2000,
        "transition_ms": 200
      }

  response = RestClient.post url, {slideshow_spec: payload.to_json, multipart: true, access_token: access_token}
# POST JSON
RestClient.post "http://example.com/resource", {'x' => 1}.to_json, {content_type: :json, accept: :json}

# POST Multipart
# Usually not needed if you don't want to upload a file
RestClient.post '/data', {:foo => 'bar', :multipart => true}

# POST x-www-form-urlencoded
RestClient.post('https://httpbin.org/post', {foo: 'bar', baz: 'qux'})