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

前端 未结 8 876
再見小時候
再見小時候 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:28

    Updated details following release of .Net Core 1.0.0

    startup.cs

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

    project.json

    "dependencies": {
        "Microsoft.AspNetCore.Mvc": "1.0.0",
        "Microsoft.AspNetCore.Mvc.Formatters.Xml": "1.0.0",
    

    For more help see Shawn Wildermuths blog post on the subject: Content Negotiation in ASP.NET Core

提交回复
热议问题