How can I force asp.net webapi to always decode POST data as JSON
Posted
by
Nathan Reed
on Stack Overflow
See other posts from Stack Overflow
or by Nathan Reed
Published on 2012-09-12T10:01:48Z
Indexed on
2012/09/12
15:38 UTC
Read the original article
Hit count: 371
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?
© Stack Overflow or respective owner