0

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.

2
  • 3
    Please show your code. Commented Sep 1, 2016 at 11:22
  • Set the request header: Content-Type text/plain Commented Sep 1, 2016 at 11:28

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Send the object as string (in its serialized format). For example

YourMethod([FromBody]string json)

2 Comments

It arrives as null.
Then you are not sending it properly. Make sure that you use the right headers. (ex: Content-Type: application/json). There's a tool called postman to test your APIs with
0

Just read the reuest content like this:

public Task<IHttpActionResult> Post() {
    var str = await Request.Content.ReadAsStringAsync();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.