Answer the question
In order to leave comments, you need to log in
How to process post request with json in c#?
Hello!
I need help, I apparently google terribly, but I couldn’t find the simplest example of processing a post request with json, in my case json just arrives with 2 user, text parameters
and how can I accept this very data?
In response, I will send a plain text, but the most important thing here is to process the request
Thanks in advance for your help
Answer the question
In order to leave comments, you need to log in
Use HttpClient and NewtonsoftJson library. Something like this https://stackoverflow.com/questions/6117101/postin...
Roman designed)
You can try like this, but it's better to use Task\await instead of getAwaiter
string str = Request.Content.ReadAsStringAsync().GetAwaiter().GetResult();
[HttpPost]
[Route("some/my/route")]
public string TestMethod(SomeClassModel model)
{
return "Hello from http post web api controller: " + model.Value;
}
public class SomeClassModel
{
public string Value { get; set; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question