Tuvia Khusid
Tuvia Khusid

Reputation: 872

Request for simple parameter in Postman is not working

I am new to Postman. The Get queries work fine but I can't send Post. I work with Net .Core. In my controller I have:

[HttpPost]
public IActionResult Post(Order model)
{
    return Ok();
}

I am getting error 400 if I am trying to add Content-Type manually or 415 if I leave it as is and just set JSON. Postman screenshot

Upvotes: 0

Views: 1160

Answers (1)

itminus
itminus

Reputation: 25350

That's because your payload is sent as querystring instead of appliation/json.

  1. The Params becomes querystring in the URL
  2. I didn't see there's a green dot besides the Body. It's likely that you didn't specify a body. In other words, the Body is empty.

Your Screenshot

It seems that you want to send a payload of application/JSON to server. If that's the case, make sure:

  1. Add a header of Content-Type: application/json in Headers
  2. Add a well-formatted JSON payload in the Body Tab:

    enter image description here


By the way,

  1. A controller annotated with [ApiController] expects a payload of application/json by default, which means the clients need send a well-formatted JSON with header of application/json.
  2. However, if you're using a plain controller instead of [ApiController], the body payload by default should be a form. In most cases they'll be application/x-www-form-urlencoded.

PostMan allows us to sends payload of different Content-Types. Please do check the related radio button when there's a need.

Upvotes: 1

Related Questions