0

I have a webapp that is currently set to output text in JSON format. I changed this by adding the following to the webapiconfig.sys for JSOn support. Works fine. And when I remove support, XML works fine.

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

However, I want an additional function in the controller to output items to XML as well. Is there a way to send the header with the output to display in XML? Should I change something in the webapiconfig?

Brad
  • 47
  • 6
  • I'm not quite sure what exactly you are asking but if your controller supports both JSON as well as XML the client (e.g. Chrome or Fiddler) can send HTTP-headers to specify what media type it wants to receive: `Accept: application/json` or `Accept: application/xml`. – venerik Nov 12 '15 at 18:43
  • Ok, that makes sense. Should I add the medatypeheaders for application/json to the webapiconfig? – Brad Nov 12 '15 at 18:54
  • I'm not sure. Have look [here](http://stackoverflow.com/questions/9847564/how-do-i-get-asp-net-web-api-to-return-json-instead-of-xml-using-chrome) – venerik Nov 12 '15 at 19:07

0 Answers0