The approximate code:
params = %{query: "https://www.lol.com"}
params = Jason.encode!(params)
HTTPoison.post(url, params, headers, @options)
The approximate request and response:
[
{
"request": {
"body": "{\"query\":\"https://lol.com\"}",
"url": "https://url.com",
"headers": {
"Authorization": "***",
"Content-Type": "application/json"
},
"method": "post",
"request_body": ""
},
"response": {
"binary": false,
"type": "ok",
"body": "{\"message\":\"Bad Request\"}\n",
"headers": {
"content-type": "application/json",
"content-length": "26"
},
"status_code": 400
}
}
]
Inspecting the body also returns "{\"query\":\"https://lol.com\"}"
As far as I can tell, it’s from the extra slash that comes after .com
to escape the double quote.
What I’ve tried:
Building the body in a sigil like these:
~S({"query":"https://lol.com"})
~s<{"query":"https://lol.com"}>
Replacing the slash with String.replace
Using req
instead of HTTPoison
This is a 3rd party API so I don’t have control over how their server receives it. Any further ideas for a client-side solution (the client being my Elixir code)?
I can get a curl request working with all the same params, but I can’t make it work in Elixir.
These seem to fail because Elixir always represents JSON object strings with escaped quotes.
curl 'https://url.com' 'Content-Type: application/json' -d '{\n "query": "https://lol.com" }