How should I send this JSON in Faraday using the post method with the "application/x-www-form-urlencoded" and "multipart/form-data;" headers?
message = {
"name":"John",
"age":30,
"cars": {
"car1":"Ford",
"car2":"BMW",
"car3":"Fiat"
}
}
I've tried:
conn = Faraday.new(url: "http://localhost:8081") do |f|
f.request :multipart
f.request :url_encoded
f.adapter :net_http
end
conn.post("/", message)
This cURL request works
curl -X POST \
http://localhost:8081 \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
-F 'message=2018-12-27 12:52' \
-F source=RDW \
-F object_type=Responses
But I don't quite know how to get this working in Faraday. Also the data in the cURL request isn't nested JSON, so I need to be able to dynamically create the body of the request as I won't know ahead of time the exact structure of the JSON.
And please ask any questions if you need more details or clarity.
Thanks!
hash.to_json
does not. – Skinned