How do I set or remove the Default Response Content Type Using SwashBuckle

被刻印的时光 ゝ 提交于 2021-02-10 12:56:57

问题


The default response content type when using SwashBuckle is text/plain. How can I change the default to be application/json or even remove text/plain?


回答1:


The response content of an end point is not determined by Swashbuckle but by the formatters set in the configuration of your ASP.NET Web API project.

To remove the text/plain content type and only support application\json you could add this to the Register method of your WebApiConfig:

GlobalConfiguration.Configuration.Formatters.Clear();

var jsonFormatter = new JsonMediaTypeFormatter();
jsonFormatter.SupportedMediaTypes.Clear();
jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue('application\json'));

GlobalConfiguration.Configuration.Formatters.Add(jsonFormatter);


来源:https://stackoverflow.com/questions/36622475/how-do-i-set-or-remove-the-default-response-content-type-using-swashbuckle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!