Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to receive str it can be json or xml. the following code the post accepts the json but when I post xml the post is null. the get sends xml or json and the post accepts the json it is is the accepting xml that is the issue

C#
[Route("api/[controller]")]
    public class CancelController : Controller
    {
        [HttpGet("get.{format}"), FormatFilter]
        public IEnumerable<BatchData> Get()
        {
            List<BatchData> cancel = new List<BatchData>
                {
                    new BatchData { BatchNumber = "1"},
                    new BatchData { BatchNumber = "2"}
                };
            return cancel;
        }

        [HttpPost("post.{format}"), FormatFilter]
        public BatchData Post([FromBody] BatchData cancel)
        {
            if (ModelState.IsValid)
            {
                return cancel;
            }
            else
            {
                return cancel;
            }
        }
}


What I have tried:

I am not sure what else to try like I said it works for json in the post but when I send xml the cancel is null
there is no error just doesn't recieve the data
this is the data I am submitting as raw in postman
<batchdata><batchnumber>1234
Posted
Updated 15-Apr-21 6:04am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900