I am making a post request in elixir using hackney, which appears to be functioning properly, but on the receiving service the body is empty.
Is there a hackney option that I am missing? I've tried sending the body as a charlist as well as a native string.
msg = Jason.encode!(%{message: "hello"})
{:ok, 200, _, body} = :hackney.post(
"http://localhost:2002/api/some/endpoint",
[
{'Content-Type', 'application/json'}
],
msg,
[:with_body]
)
IO.inspect(Jason.decode!(body), label: "response")
# => {:ok, "ok"}
That sent the body for me, but it appears to want "application/json" as a binary instead of a charlist. When I did a charlist I got a numeric content type header.
It's possible your server would get that content type and handle the request body in such a way it doesn't appear to be getting sent.
This is what I ended up with (I also changed the header name to a lowercase binary for consistency, but it doesn't seem necessary)
:hackney.post("http://localhost:2002/api/some/endpoint", [{"content-type", "application/json"}], msg, [:with_body])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With