c# - ASP.Net WebAPI has different content type in different user agents -


i trying learn asp.net webapi, , having hard time figuring out going on. created small application contains action this:

public ihttpactionresult hello()  {     return ok("hi"); } 

this works fine, @ in browser. see:

<string xmlns="http://schemas.microsoft.com/2003/10/serialization/">hi</string> 

this using chrome. use extension see content type , text/xml. want check things out further use postman rest client test it. there see: "hi" , content type application/json. confused. figured postman changing content type, sure installed rest client returned application/json. in internet explorer attempts download result json file. heck going on. there way can have universal content type?

web api can serialise responses xml or json. reads content-type http header determine one. use fiddler examine requests brower. postman passes application/json content type default - json response.

you can add following code webapiconfig file remove xml serialiser , return json.

var appxmltype = config.formatters.xmlformatter.supportedmediatypes.firstordefault(t => t.mediatype == "application/xml");     config.formatters.xmlformatter.supportedmediatypes.remove(appxmltype); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -