I have an POST API end point, i.e.
[Route("api/{parameter1}/employee")]
[HttpPost]
public Employee RegisterEmployee(string parameter1, [FromBody] string parameter2)
Now, I want to hit this API from postman.
My request URL is:
http://localhost:xxxxx/api/parameter1/employee
And the body is:
So, in this way I am getting: 415 Unsupported Media Type error.
If I try other ways then i am able to hit the API, but parameter2 is always coming as null.
So, how should I pass the parameter2 value in postman?
Try setting content type to application/json
. JSON String inputs thankfully capture as strings in ASP.NET Core.
Alternatively, you could read the body string from the request stream:
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
return await reader.ReadToEndAsync();
}