Reputation: 537
I have a Web API controller that has a POST method which receives data from the request body, and all it does is send it to another web service, so deserializing the data is not necessary. How can I disable the auto deserialization done by the Web API?
public IHttpActionResult Post([FromBody]string data)
{
//Post with http client...
}
The data arrives as null with this signature.
Upvotes: 0
Views: 3706
Reputation: 3050
Just read the reuest content like this:
public Task<IHttpActionResult> Post() {
var str = await Request.Content.ReadAsStringAsync();
}
Upvotes: 0
Reputation: 347
Check this:
public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
{
var data = await request.Content.ReadAsStringAsync();
// do stuff with the content
}
More about the solution: http://bizcoder.com/posting-raw-json-to-web-api
Upvotes: 1
Reputation: 600
Send the object as string (in its serialized format). For example
YourMethod([FromBody]string json)
Upvotes: 0