【发布时间】:2021-12-24 06:10:27
【问题描述】:
当我运行我的 Phoenix 框架测试时,我收到了这个错误:
** (Phoenix.NotAcceptableError) no supported media type in accept header.
Expected one of ["html"] but got the following formats:
* "application/json" with extensions: ["json"]
To accept custom formats, register them under the :mime library
in your config/config.exs file:
config :mime, :types, %{
"application/xml" => ["xml"]
}
And then run `mix deps.clean --build mime` to force it to be recompiled.
即使我将此行添加到我的 config.exs 我仍然收到错误:
config :mime, :types, %{
"application/json" => ["json"]
}
我做错了什么?
【问题讨论】:
-
您在路由器管道的某处有
plug :accepts, ["json"]吗? (见docs) -
就是这样!我将路由放在 :browser 范围内,我应该将其更改为 :api 以接受 json。
标签: elixir phoenix-framework mime-types mime