0

I have an ASP.NET Core controller that responds to POST requests and accepts data as application/x-www-form-urlencoded

[HttpPost]
[Consumes("application/x-www-form-urlencoded")]
public async Task<IActionResult> RegisterPayment([FromForm]PaymentDetails data)
{
//registerpayment
}

By using Postman, when I POST x-www-form-urlencoded with this body:

orderid:2552
amount:100

it works, and data parameter is correctly bound.

However if I POST it using querystring format like this

orderid=2552&amount=100

It does not bind, all fields in data are null.

I would expect the data to be bound correctly, even when using querystring format, that is urlencoded after all.

ekad
  • 13,718
  • 26
  • 42
  • 44
Federico
  • 11
  • 1

1 Answers1

0

Unlike GET requests, POST requests are not intended to contain query strings. Typically one would put all params in the query string for GET and all params in the body for POST.

It is likely that your framework of choice is ignoring query strings for POST requests.

For a more in-depth discussion, suggest you check this and this out.

Yuan Ruo
  • 36
  • 2
  • 5