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

后端 未结 8 2271
自闭症患者
自闭症患者 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:59

    For Core 2.x versions, you have to do two things. First thing is you need to add following code inside the ConfigureServices method of Startup.cs file.

    services.AddMvc()
    .AddMvcOptions(o => o.OutputFormatters.Add(
        new XmlDataContractSerializerOutputFormatter())
    );
    

    And then add the Accept "application/xml" header to the request as below on Postman. Then XML formatted result will be returned.

提交回复
热议问题