Coding Away Coding Away - 1 month ago 4
AngularJS Question

Chrome vs. Postman showing different value for Web api data in XML vs JSON

If I make web api call with Chrome Browser it is displaying XML data in which there is the "proper" name


However if I use Postman to make the same call I get JSON back and

"DeviceStatus": 3,

Both are the same URL

Thus even then my Angular website is displaying the number "3" ( there are 1 and 2 etc.. )

Why is this?


Chrome is making a request from your Web Api, an attempt to do a content negotiation is taking place and if I cannot fine a formatter from you accept header ... It will try the first formatter in the list of formatters to write that response back to the client ( chrome)

Sometimes you will get json other times xml , i have refreshed my browser and seen it happen myself.

A few tricks

var json = config.Formatters.JsonFormatter;
    json.SerializerSettings.PreserveReferencesHandling =


Or maybe try adding in WebApiConfig.cs

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

I would personally do the 2nd approach

Return JSON response by default If you execute GET request, ASP.NET Web API framework will return response in XML, JSON or any other format depending on accept header of request. Chorme and Firefox browser has XML as default value for accept header whereas IE has JSON as default value. So if you execute request through Chrome or Firefox you will get response in XML and if you use IE you will get JSON response.

If you want your Web API should return JSON response as default you will have to configure JSON Media Type Formatter.

Open WebApiConfig.cs file from App_start folder and add that code after route configuration.

~ reference unknown what saved in a OneNote page of mine...