How to pass string in post request body in postman

10,871

Try setting content type to application/json. JSON String inputs thankfully capture as strings in ASP.NET Core.

enter image description here

Alternatively, you could read the body string from the request stream:

using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{  
    return await reader.ReadToEndAsync();
}
Share:
10,871
Dark Matter
Author by

Dark Matter

This is your life and it's ending one minute at a time.

Updated on July 18, 2022

Comments

  • Dark Matter
    Dark Matter almost 2 years

    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:

    enter image description here

    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?