I have a .net6 API hosted on windows server on IIS 10.
I have the following controller that has an endpoint with POST method and the body content type is x-www-form-urlencoded
The problem is the body is always comes null on the server.
What could be the cause of this issue?
namespace testapp.Controllers
{
public class TestInput
{
public string? Name { get; set; }
public int Age { get; set; }
}
[Route("api/[controller]")]
[ApiController]
public class TestController : ControllerBase
{
// POST api/<TestController>
[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
public TestInput Post([FromForm] TestInput value)
{
return value;
}
}
}
here is how I make the API call
curl --location 'https://localhost:7158/api/Test' \
--header 'accept: */*' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'name=john doe' \
--data-urlencode 'age=22'
- I have tried to disable the firewall on the server
- I have disabled all the request filtering on IIS
but still have the issue