What is wrong with this ASP.Net and Fiddler example?

asp.net-web-api, fiddler

Solution

(1) By default, simple types are taken from the URI. To read a simple type from the request body, add the [FromBody] attribute to the parameter.

public string Post([FromBody] string abc)

(2) '{"abc": "def"}' defines an object with a property named "abc" - to send a JSON string, the request body should just be "def"

Problem

I am using Visual Studio 2012 RC. I am using the default routes and have the following Web API controller: ``` public class FooController : ApiController { // GET api/foo public IEnumerable<string> Get() { return new string[] { "value1", "value2" }; } // GET api/foo/5 public string Get(int id) { return "value"; } // POST api/foo public string Post(string abc) { Console.WriteLine("value: {0}", abc); return "foo" + abc; } // PUT api/foo/5 public void Put(int id, string value) { } // DELETE api/foo/5 public void Delete(int id) { } } ``` I wanted to do a simple test of POST in Fiddler, so I have Request Headers User-Agent: Fiddler Content-Type: application/json Request Body {"abc": "def"} When I debug the request, the parameter abc comes in as null, not "def". Is there something wrong with my Fiddler syntax?

Original source