After reading the Asp.net web API, we found that using web API to create restful services is much more convenient than using WCF. Because I use a plug-in restclient in Firefox for testing, I found that the returned results are always in XML format, not the JSON format I want, if IE is used, it is in JSON format. The reason is that the default Firefox header information accept is application/XML, While IE is application/JSON. The corresponding solution is to add the header
Accept: Application/JSON
Another way is to modify the server segment so that the web API ignores the client settings, and addGlobalconfiguration. configuration. formatters. xmlformatter. supportedmediatypes. Clear ();
Protected VoidApplication_start ()
{
Arearegistration. Registerallareas ();
Webapiconfig. Register (Globalconfiguration. Configuration );
Filterconfig. Registerglobalfilters (Globalfilters. Filters );
Routeconfig. Registerroutes (Routetable. Routes );
Bundleconfig. Registerbundles (Bundletable. Bundles );
Globalconfiguration. Configuration. formatters. xmlformatter. supportedmediatypes. Clear ();
}