How to properly consume an C# APi?

So far i try this:

iex(18)> url = ""                                                          ""
iex(19)> data = %{username: "testuser", password: "testpass"}                                                          %{password: "testpass", username: "testuser"}
iex(20)> postdata = URI.encode_query(data)
iex(21)> headers = [{"Content-Type", "application/json"}]                
[{"Content-Type", "application/json"}]

But I got this error.

 %HTTPoison.Response{body: "{\"Message\":\"The request contains an entity body but no Content-Type header. The inferred media type 'application/octet-stream' is not supported for this resource.\"}",
  headers: [{"Cache-Control", "no-cache"}, {"Pragma", "no-cache"},
   {"Content-Type", "application/json; charset=utf-8"}, {"Expires", "-1"},
   {"Server", "Microsoft-IIS/8.5"}, {"X-AspNet-Version", "4.0.30319"},
   {"X-Powered-By", "ASP.NET"}, {"Date", "Thu, 16 Mar 2017 07:06:15 GMT"},
   {"Content-Length", "164"}], status_code: 415}}

Using postman, its working fine

Any Idea?


In your mix.lock file what version of hackney is specified? 1.6.6 is retired, if you see that be sure to upgrade.


Also just as heads up, if you start seeing :closed connection results this thread will help you 18.3.4 + Erlang TLS1.2 [+ IIS] Issues

I got really bamboozled with this issue when trying to integrate with the MS graph API/oauth.


My hackney version is 1.6.6. Thank you very much.