我们使用MVC编写了web api。 在某些机器上,当我们在Firefox浏览器中输入url时,显示纯文本作为响应 我想限制浏览器以XML格式显示响应。 有没有办法实现这一目标。
答案 0 :(得分:0)
是的,您需要限制您的API以仅返回XML。
void ConfigureApi(HttpConfiguration config)
{
// Remove the JSON formatter
config.Formatters.Remove(config.Formatters.JsonFormatter);
}
您可以在此处找到有关Web API内容协商的更多信息:http://www.asp.net/web-api/overview/formats-and-model-binding/content-negotiation
在这里: How do I specify if I want JSON or XML in ASP.NET Web API?