Why won't my ASP.Net Core Web API Controller return XML?

后端 未结 8 2263
自闭症患者
自闭症患者 2020-12-14 08:28

I have the following simple Web API controller:

    // GET: api/customers
    [HttpGet]
    public async Task Get()
        {
        var         


        
8条回答
  •  一个人的身影
    2020-12-14 08:52

    For MVC 1.1 you need to add the Package Microsoft.AspNetCore.Mvc.Formatters.Xml and edit your Startup.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc(options => { options.RespectBrowserAcceptHeader = true; })
            .AddXmlSerializerFormatters()
            .AddXmlDataContractSeria‌​lizerFormatters();
    }
    

    Now you can set the Accept Header:

    XML: application/xml

    JSON: application/json

提交回复
热议问题