2

I am trying to convert this CURL request:

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

To a HTTPClient request but all my attempts results in 400 Bad Request. Here's what I've tried:

  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}

Any ideas?

Dan Def
  • 1,836
  • 2
  • 21
  • 39
WagnerMatosUK
  • 4,309
  • 7
  • 56
  • 95

1 Answers1

0

Your requests are not equivalent. I guess you are mixing JSON, Multipart and x-www-form-urlencoded formats here.

RestClient supports all three formats (examples taken from https://github.com/rest-client/rest-client/blob/master/README.md)

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

Looks like your curl sample uses application/x-www-form-urlencoded, while your Ruby sample uses multipart/form-data.

For some background information, check

claasz
  • 2,059
  • 1
  • 14
  • 16