问题
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