ASP.NET Core 1.0 Web API doesn't return XML

前端 未结 8 881
再見小時候
再見小時候 2020-12-19 02:12

How can I have my vnext API to return XML and JSON ?

I thought that using content-type with application/xml would work as it was before. Note that I tryed with Accep

8条回答
  •  借酒劲吻你
    2020-12-19 02:41

    MVC 6 RespectBrowserAcceptHeader is false by default. Hence it will bypass the content negotiation. And that's why probably you're getting XML always after enabling the XML formatter.

    You can turn the RespectBrowserAcceptHeader to true by adding the following to your startup file:

    services.Configure(options =>
            {
                options.RespectBrowserAcceptHeader = true;
            });
    

提交回复
热议问题