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'})