I am getting some json data posted to my asp.net webapi, but the post parameter is always coming up null – the data is not being serialized correctly. The method looks something like this:
public HttpResponseMessage Post(string id, RegistrationData registerData)
It seems the problem is that the client (which I have no control over) is always sending the content-type as x-www-form-urlencoded, even though the content is actually json. This causes mvc to try to deserialize it as form data, which fails.
Is there any way to get webapi to always deserialize as json, and to ignore the content-type header?
I found the answer here: http://blog.cdeutsch.com/2012/08/force-content-types-to-json-in-net.html
This code needs to be added to Application_Start or WebApiConfig.Register
It tells the json formatter to accept every type, and removes the form and xml formatters