Ron Ron - 1 year ago 109
C# Question

Testing WebApi with Fiddler POST

GET works fine. In the Controller I have this method:

public IHttpActionResult Post(Product product)
var isSaved = productService.SaveProduct(product);
if (isSaved == true) return Ok();
else return BadRequest();

The problem is, product is null. I get to this method (via a breakpoint) but am not sure why the product is null. Here's what's in Fiddlers Composer:

User-Agent: Fiddler
host: localhost:53882
Content-Type: application/json; charset=utf-8
Content-Length: 54

And this is the Fiddler request body:

name: Dress,
price: 39.90,

enter image description here
There's no model. It's all in the db (edmx). It works for getting a list of products, or a product by product id.

Answer Source

The name in your request body is missing the double quotes. Make sure the cases matches as your model because it is case-sensitive.

  Name: "Dress",
  Price: 39.90,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download