ASP. NET Web APIs are displayed in XML format in Firefox. How can I switch to JSON format?

Source: Internet
Author: User

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 ();


}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.