Skip to content
Fix Code Error

How do I get ASP.NET Web API to return JSON instead of XML using Chrome?

March 13, 2021 by Code Error
Posted By: Anonymous

Using the newer ASP.NET Web API, in Chrome I am seeing XML – how can I change it to request JSON so I can view it in the browser? I do believe it is just part of the request headers, am I correct in that?

Solution

I just add the following in App_Start / WebApiConfig.cs class in my MVC Web API project.

config.Formatters.JsonFormatter.SupportedMediaTypes
    .Add(new MediaTypeHeaderValue("text/html") );

That makes sure you get JSON on most queries, but you can get XML when you send text/xml.

If you need to have the response Content-Type as application/json please check Todd’s answer below.

NameSpace is using System.Net.Http.Headers.

Answered By: Anonymous

Related Articles

  • Is CSS Turing complete?
  • How to find Control in TemplateField of GridView?
  • WebAPI: Null values not suppressed by Default XML Serializer
  • How to use Servlets and Ajax?
  • Accessing Session Using ASP.NET Web API
  • GLYPHICONS - bootstrap icon font hex value
  • No 'Access-Control-Allow-Origin' header is present…
  • Error Stack Overflow when trying to hide buttons in…
  • How do we control web page caching, across all browsers?
  • Web API Put Request generates an Http 405 Method Not…
  • Error creating bean with name
  • XMLHttpRequest cannot load ✘✘✘ No…
  • Is it possible to apply CSS to half of a character?
  • Identifying and solving…
  • Failed to serialize the response in Web API with Json
  • ASP.NET Core return JSON with status code
  • How to use java.net.URLConnection to fire and handle…
  • JSON.NET Error Self referencing loop detected for type
  • ember: understand errors
  • Select Tag Helper in ASP.NET Core MVC
  • What is the equivalent of node.js .getHeaders() in…
  • Displaying Total in Footer of GridView and also Add…
  • How can I find the product GUID of an installed MSI setup?
  • How should a model be structured in MVC?
  • grid controls for ASP.NET MVC?
  • Simple C example of doing an HTTP POST and consuming…
  • JQuery, Spring MVC @RequestBody and JSON - making it…
  • Accessing the web page's HTTP Headers in JavaScript
  • during wct test: Failed to load resource: the server…
  • Backend and frontend MVC
  • An item with the same key has already been added
  • How can I avoid Java code in JSP files, using JSP 2?
  • ExpressJS How to structure an application?
  • The definitive guide to form-based website authentication
  • Aurelia, navigate is not updating viewport
  • javax.faces.application.ViewExpiredException: View…
  • My Application Could not open ServletContext resource
  • Calculating score on a quiz test using asp.net C#…
  • Using Auto Layout in UITableView for dynamic cell…
  • How to generate JAXB classes from XSD?
  • How do I add BundleConfig.cs to my project?
  • How to change the color of vaadin-select-text-field…
  • CORS GET returns an empty response body in Firefox
  • cors issue with vue and dotnet
  • Why am I getting "(304) Not Modified" error on some…
  • Logging best practices
  • org.springframework.beans.factory.BeanCreationExcept…
  • What is a NullReferenceException, and how do I fix it?
  • Throw HttpResponseException or return…
  • How can I use a reportviewer control in an asp.net…
  • Rails rspec returns no examples found when…
  • Worker Script Failing to Load for Vue Webpack Built App
  • org.springframework.beans.factory.NoSuchBeanDefiniti…
  • How to enable CORS in ASP.net Core WebAPI
  • "An exception occurred while processing your…
  • Visual Studio debugging/loading very slow
  • Database development mistakes made by application developers
  • commandButton/commandLink/ajax action/listener…
  • How to get active user's UserDetails
  • Smart way to truncate long strings
  • Multiple actions were found that match the request…
  • How to handle static content in Spring MVC?
  • Playing HTML5 video on fullscreen in android webview
  • How can I manually compile a svelte component down…
  • SQL query return data from multiple tables
  • AngularJS POST Fails: Response for preflight has…
  • Posting form to different MVC post action depending…
  • Start redis-server with config file
  • Active tab issue on page load HTML
  • How does Access-Control-Allow-Origin header work?
  • How do I return the response from an asynchronous call?
  • How to support HTTP OPTIONS verb in ASP.NET…
  • The type or namespace name does not exist in the…
  • JavaScript MVC vs ASP.NET MVC (Pattern Differences)
  • How to submit Polymer forms to PHP and display response
  • CRUD - Create select dropdown list autofills another…
  • Angular - Set headers for every request
  • Download Excel file via AJAX MVC
  • Understanding the internal structural dependencies…
  • Right way to do navigation with Ember
  • Does it make sense to integrate backbone.js with ASPNET MVC?
  • What does do?
  • System.Data.SqlClient.SqlException: Login failed for user
  • aurelia-fetch-client create request headers on the fly
  • Asp.net core 3.1 with Razor Pages redirects to the…
  • Spring MVC: difference between and tags?
  • All ASP.NET Web API controllers return 404
  • How to add Web API to an existing ASP.NET MVC 4 Web…
  • How to return a file (FileContentResult) in ASP.NET WebAPI
  • Cross Domain Request w/ Cors
  • How does ASP.NET Core MVC serialize responses to JSON?
  • Why does my instance of Axios not return the…
  • Issue adding access token to header in Backbone: It…
  • Spring MVC + JSON = 406 Not Acceptable
  • Run chrome in fullscreen mode on Windows
  • How to filter a RecyclerView with a SearchView
  • MVC 4 @Scripts "does not exist"
  • Polymer routing: inner routes not reflecting
  • OpenIddict Roles/Policy returns 403 Forbidden
  • "Thinking in AngularJS" if I have a jQuery background?

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

The type or namespace name could not be found

Next Post:

Python string.replace regular expression

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error