Y
Y
yamakasi_habr2022-03-10 01:24:27
ASP.NET
yamakasi_habr, 2022-03-10 01:24:27

How to accept JSON to ASP.NET API controller?

A POST request comes to the controller. I'm trying to accept as a string - it doesn't work, it gives an error.

622927d35d58b955380808.png

It seemed to work before, but now it doesn't work. I know that you can accept a model, but I would like a string. Help pliz I beg on my knees

CONSOLE.WRITELINE HERE NOT TO DO. THIS I WROTE LATER

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2022-03-10
@vabka

[HttpPost(Name = "VkCallBackReceiver")]
public ActionResult Post([FromBody]string json) {
  Console.WriteLine(json);
  return Ok();
}

I know that you can accept a model, but I would like a string.

What for? If you need to dynamically parse, then immediately accept JsonDocument then

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question