No supported media type in accept header

Hi all

When I make a request from the server, I’ve got

[debug] ** (Phoenix.NotAcceptableError) no supported media type in accept header, expected one of ["json", "xml"]
    (phoenix) lib/phoenix/controller.ex:961: Phoenix.Controller.refuse/2
    (northwind) web/router.ex:12: Northwind.Router.api/2
    (northwind) web/router.ex:1: Northwind.Router.match_route/4
    (northwind) web/router.ex:1: Northwind.Router.do_call/2
    (northwind) lib/northwind/endpoint.ex:1: Northwind.Endpoint.phoenix_pipeline/1
    (northwind) lib/plug/debugger.ex:123: Northwind.Endpoint."call (overridable 3)"/2
    (northwind) lib/northwind/endpoint.ex:1:
    (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
    (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

The requested header looks as follow:

[{"host", "localhost:4000"}, {"connection", "keep-alive"},
 {"accept", "application/xml"}, {"sap-contextid-accept", "header"},
 {"accept-language", "en-US"}, {"maxdataserviceversion", "3.0"},
  "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"},
 {"referer", "http://localhost:4000/"},
 {"accept-encoding", "gzip, deflate, sdch, br"},

and the configured pipeline:

  pipeline :api do
    plug Northwind.HeadersPlug #For output http header
    plug :accepts, ["json", "xml"]

My problem is, that phoenix does not accept the request and I do not why.

I think the problem is because of, but not sure:
{"sap-contextid-accept", "header"}
I am using OpenUI5 frontend framework, for request data from phoenix.


My hunch is that “application/xml” is not being recognized as a “xml” mime type. Let’s check that:

$ iex -S mix
iex> MIME.extensions("application/xml")

That’s it. The fix is easy, just configure the mime project in your config/config.exs:

config :mime, :types, %{
  "application/xml" => ["xml"]

And then run mix deps.clean --build mime to force mime to be recompiled across all environments. Now you should be good to go!


First of all, thanks so much for your response.
Where can I find the MIME module?

It is here:

If for some reason it is not available in your code, try updating your plug version with mix deps.update plug (or check your mix.exs file to see if you can upgrade to latest).

1 Like

thanks jose, I will try it.