Simple ApiController method:
public class TestController : ApiController
{
public void TakeIt(MyObject o){
Console.Write(o.ToString());
}
}
Simple data type:
public class MyObject{
public string V1{ get; set; }
public string V2{ get; set; }
}
Simple post:
POST http://localhost:11026/api/test/takeit HTTP/1.1
Accept: application/json
Content-Type: application/json
Host: localhost:11026
{"V1":"Something","V2": "Something else"}
For some reason the MyObject o will not automatically bind from the JSON form post body (even with [FromBody] inserted before the parameter on the method.
Am I doing something wrong?
SOLUTION (DUH!)
To debug my incoming requests, I had put this in my global.asax (because I was failing to get the requests to flow through Fiddler) so I could inspect them first
protected void Application_BeginRequest()
{
using (Stream receiveStream = Request.InputStream)
{
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
var content = readStream.ReadToEnd();
Console.WriteLine(content);
}
}
}
This was stopping anything down the line from reading the posted data. Soon as I removed that, the automatic model binding worked fine.