ASP.NET Core 1.0 Web API doesn't return XML

前端 未结 8 879
再見小時候
再見小時候 2020-12-19 02:12

How can I have my vnext API to return XML and JSON ?

I thought that using content-type with application/xml would work as it was before. Note that I tryed with Accep

8条回答
  •  北海茫月
    2020-12-19 02:33

    Updated answer for ASP.NET Core 1.1:

    Startup.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc(config => {
            config.RespectBrowserAcceptHeader = true;
            config.InputFormatters.Add(new XmlSerializerInputFormatter());
            config.OutputFormatters.Add(new XmlSerializerOutputFormatter());
        });            
    }
    

    Csproj:

    
    
    

提交回复
热议问题