Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir HTTPoison post请求_Elixir - Fatal编程技术网

Elixir HTTPoison post请求

Elixir HTTPoison post请求,elixir,Elixir,我正在使用HTTPoison库进行post请求这是我的方法 def do_request(method, url, body \\ "", headers \\ [], options \\ []) do headers = [{"Authorization", "Bearer #{Application.get_env(:app, :access_token)}"}] case body do {:json, json} -> headers = [{"Cont

我正在使用HTTPoison库进行post请求这是我的方法

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

对这个问题有什么想法吗?

这就是全部原因吗?在你的应用程序中没有从
do_request
中提到任何行?我认为你粘贴了错误的代码片段。您仅粘贴了带有编码的片段。问题可能出在试图解码请求的
过程\u响应
的某个地方。毒物返回一个结构,您需要调用
result.body
从结构中获取主体。我猜你没有这么做,而是把整个结构传递给了编码器。但这只是我的猜测:)我也经常看到这种情况发生在process\u response调用
Poison.decode时!(body)
当您发出了错误的请求,因此响应是一些html文本或另一个无效的json字符串时。正如tkowal所说,这是一个黑暗中的短路,没有看到您对
process\u response