Jimi
Jimi

Reputation: 1897

asp.net API post values received are null from postmaster

I'm writing a very basic asp .net api with a simple post method. The post parameters are returning null. I've tried various ways to get the method to return the object I passed in. I created a data transfer object and I've verified that the method is getting called. What else can I check ?

post master settings ----

     url: /api/values
     params: incidentID 4
     params: incidentTitle 'this is some text'
     Content-Type: application/json


    // POST api/values
    [Route("api/values")]
    [HttpPost]
    public HttpResponseMessage Post([FromBody]incidentDTO incid)
    {
        return Request.CreateResponse(incid);

    }

Upvotes: 0

Views: 870

Answers (1)

kagundajm
kagundajm

Reputation: 1200

I assume by postmaster you meant Postman.

If you are using Postman, use the following steps:

Under Header type Content-Type with a value of application/json

Select the raw tab and enter your data as follows:

{
    "incidentId":4,
    "incidentTitle":"this is some text"
}

Click on Send.

As the post data is being read from the body, there in no need to enter any values in URL params.

Upvotes: 2

Related Questions