Reputation: 8118
This is my API:
namespace test.Api
{
[Route("api/[controller]")]
[Produces("application/json")]
public class UsersController : Controller
{
public ApplicationDbContext _context { get; set; }
public UsersController([FromServices] ApplicationDbContext context)
{
_context = context;
}
[HttpPost]
public IActionResult Login([FromBody]LoginViewModel user)
{
return this.Ok("ok");
}
}
}
And my LoginViewModel
:
namespace test.ViewModels
{
public class LoginViewModel
{
public string Username { get; set; }
public string Password { get; set; }
}
}
But it does not work:
PS: I tested the same controller with a HttpGet
request and it works fine.
Upvotes: 0
Views: 57
Reputation: 33823
You are simply sending the incorrect content-type, which is what the 415
status code is telling you.
If you change your content type from raw
to application/json
, the API will be able to process it correctly.
Upvotes: 1