I get a null value always in the post post api rest request for the controller
In my controller
[HttpPost] public HttpResponseMessage PostCustomer([FromBody]Customer customer) { System.Diagnostics.Debug.WriteLine(customer); #CustomerApp.Models.Customer System.Diagnostics.Debug.WriteLine(customer.FirstName); #null }
Model
public class Customer { public int Id { get; set; } public string LastName { get; set; } public string FirstName { get; set; } }
Request:
POST: http://localhost:21894/api/customer/postcustomer Content-Type: application/json body: {FirstName: "xxxx", LastName: 'yyyy'}
I tried the following solutions but nothing worked
https://myadventuresincoding.wordpress.com/2012/06/19/c-supporting-textplain-in-an-mvc-4-rc-web-api-application/
How to get POST data in WebAPI?
Can someone help me with the help or the correct link
Answer: I made a request for curling, instead of dealing with a postman, as if it gave me a solution
$ curl -H "Content-Type: application/json" -X POST -d '{"FirstName":"Jefferson","LastName":"sampaul"}' http://localhost :21894/api/customer/postcustomer
source share