HTTPoison post request not handled by Phoenix!

Recently, I’ve went ahead and updated all dependencies (cowboy mainly) and Elixir… Everything is working great except this extremely weird issue with HTTPoison requests. I want to hit a webhook on another Phoenix server, so I do:

HTTPoison.post(
  @webhooks_uri <> path,
  Poison.encode!(params),
  [{"Content-Type", "application/json"}],
  [ssl: [{:versions, [:'tlsv1.2']}]]
)

I am getting a response 400 Internal Server Error. Debug logs from the receiving server is showing that the params are empty, even though I’m sending the account uid.

Testing through postman, the receiving server is getting the request just fine! So, I tried to hit httpbin.org/post through the HTTPoison code, and got this:

 %HTTPoison.Response{body: body,
  headers: [{"Server", "nginx"}, {"Date", "Wed, 15 Mar 2017 18:36:58 GMT"},
   {"Content-Type", "application/json"}, {"Content-Length", "436"},
   {"Connection", "keep-alive"}, {"Access-Control-Allow-Origin", "*"},
   {"Access-Control-Allow-Credentials", "true"}], status_code: 200}}

# decoded body for readability:
%{"args" => %{},
  "data" => "{\"account_uid\": \"91c43585-a38d-4edf-ad25-9da62fc9aecd\"}",
  "files" => %{}, "form" => %{},
  "headers" => %{"Content-Length" => "55",
    "Content-Type" => "application/json, application/json",
    "Host" => "httpbin.org", "User-Agent" => "hackney/1.6.6"},
  "json" => %{"account_uid" => "91c43585-a38d-4edf-ad25-9da62fc9aecd"},
  "origin" => "94.202.255.10", "url" => "http://httpbin.org/post"}

Nothing seems out of place … Where should I look next? tcpdump?

3 Likes

HTTPoison was v0.10.0, and hackney was on a retired 1.6.6 version … Trying to resolve that and see if that helps.

Update: This resolved it … Lesson learned, never trust retired deps!

3 Likes

I would try to send the same request using curl to see if it works

1 Like

I’m having issues using CLI requests because my server has self-signed certs, but thanks for the tip! Looking at the httpbin again, I can see the content type is malformed :cry:

1 Like