HTTPoison发布请求

时间:2016-06-15 10:09:43

标签: elixir

我正在使用HTTPoison lib来发帖请求我的方法

def do_request(method, url, body \\ "", headers \\ [], options \\ []) do
  headers = [{"Authorization", "Bearer #{Application.get_env(:app, :access_token)}"}]

  case body do
    {:json, json} ->
    headers = [{"Content-Type", "application/json"} | headers]
    body = Poison.Encoder.encode json

    {:file, _path} -> true
    _ -> body = []
  end

  request!(method, url, body, headers, options) |> process_response
end

调用方法:

body = %{ "account_id" => "123456" }
do_request(:post, '/users/get_account', JSX.encode!(body))

但我正在

** (ArgumentError) argument error
           (jsx) src/jsx_decoder.erl:234: :jsx_decoder.value/4
         (exjsx) lib/jsx.ex:15: JSX.decode!/2
     (httpoison) lib/httpoison/base.ex:413: HTTPoison.Base.response/6

关于这个问题的任何想法?

0 个答案:

没有答案