使用 SwashBuckle 时的默认响应内容类型是text/plain
。我怎样才能将默认值更改为application/json
甚至删除text/plain
?
终点的响应内容不是由Swashbuckle
而是通过 ASP.NET Web API 项目配置中设置的格式化程序。
要删除text/plain
内容类型且仅支持application/json
你可以将其添加到Register
你的方法WebApiConfig
:
GlobalConfiguration.Configuration.Formatters.Clear();
var jsonFormatter = new JsonMediaTypeFormatter();
jsonFormatter.SupportedMediaTypes.Clear();
jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
GlobalConfiguration.Configuration.Formatters.Add(jsonFormatter);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)