Accept : application/xml
Accept: application/json
//如下设置可以支持xml和json格式输出。默认输出格式为json
services.AddControllers(configure: setup =>
{
setup.ReturnHttpNotAcceptable = true;
}).AddXmlDataContractSerializerFormatters();
//默认输出格式为Json,现在把默认格式给为XML格式输出
services.AddControllers(configure: setup =>
{
setup.ReturnHttpNotAcceptable = true;
//支持输出格式为XML
// setup.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter());
//默认输出格式为Json,现在把默认格式给为XML格式输出
setup.OutputFormatters.Insert(index:0, new XmlDataContractSerializerOutputFormatter());
})
原文地址:https://www.cnblogs.com/konglingxing/p/12425086.html
时间: 2024-10-14 05:59:13