Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I cannot create a POST request using POSTMAN, but I have no problems doing it on Swagger

I have a Controller that can receive Post requests.

public IHttpActionResult PostCreaAlimento([FromBody] Alimento alimento)
    {
        if (!ModelState.IsValid)
            return BadRequest("Invalid data.");

        return _repositorio.CreaAlimento(alimento) ? Ok(alimento) : (IHttpActionResult)NotFound();
    }

The request is correctly done on swagger, and I receive a response code 200.

But, if I try to do the same on POSTMAN, I receive an Unsupported Media File.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Request on POSTMAN

Why is this not working :/

>Solution :

Since you are using [FromBody] in the action it means that you need to send application/json contentType
so select Body=> raw => json and put this in the body of Postman

{
    "AlimentoId":4,
    "Description":"testing",
    "Calorias" :400
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading