2
Answers

How to post both JSON and XML data at same time using body- form data?

Photo of Abhishek Addu

Abhishek Addu

3y
691
1

How to POST both JSON and XML data at same time using body- form data in .NET core Web API? any sample example ?

Answers (2)

1
Photo of Sachin Singh
NA 55.8k 87.9k 3y

you can design the API to accept both types as shown below but HTTP doesn't allow 2 content types at the same time, so you will have to make 2 requests.

  1. 
    [HttpPost("post.{format}"), FormatFilter]
    public int Post([FromBody]Employee employee)
    {
    // do yr work
    }
    http://localhost:1234/api/employees/Post.json
    http://localhost:1234/api/employees/Post.XML

     

0
Photo of Farhan Ahmed
63 28.3k 15.4m 3y
https://www.c-sharpcorner.com/article/combine-xml-and-json-requests-and-responses-in-asp-net-core-web-api/
https://andrewlock.net/formatting-response-data-as-xml-or-json-based-on-the-url-in-asp-net-core/