指定webapi 返回 json 格式 ; GlobalConfiguration.Configuration.Formatters.Clear()

因为 Internet Explorer 和 Firefox 发送了不同的 Accept 头,所以 web API 在响应里就发送了不同的内容类型。

 

解决方法,在 Global.asax的 Application_Start() 加入下面的代码

GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

 

image

 

参考 :http://blog.miniasp.com/post/2012/10/12/ASPNET-Web-API-Force-return-JSON-format-instead-of-XML-for-Google-Chrome-Firefox-Safari.aspx

原文地址:https://www.cnblogs.com/joeylee/p/3830046.html