How can I force asp.net webapi to always decode POST data as JSON
- by Nathan Reed
I 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 as form data, which fails.
Is there anyway to get webapi to always deserialize as json, and to ignore the content-type header?