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

Time:11-24

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.

enter image description here

CodePudding user response:

You pass json data as form data but your controller accepts request body data as raw data. You should change body type as raw data.

  • Related