I have a client that will send some string data to my web page using JSON, but when I post it, it always returns null for some reason.
Is there anything wrong with my post?
Client:
public async Task TesteAsync(string numeroserie)
{
try
{
var json = Newtonsoft.Json.JsonConvert.SerializeObject(numeroserie);
var data = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json");
var url = "https://localhost:44336/Home/Receive";
var client = new HttpClient();
var response = await client.PostAsync(url, data);
string result = response.Content.ReadAsStringAsync().Result;
MessageBox.Show(result);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return;
}
}
Server Side:
[System.Web.Http.HttpPost]
public string Receive(string json)
{
return json;
}
My server is using ASP.NET MVC.
Server side using breakpoint when the request is made
Client side using break when sending
Update: What i want to do in the end is send to my webserver a string and then return it to the client . I have no experience with json so i don't know if it's correct what i did