Web Service required this format:
{
"Data":"{\"Name\":\"HelloWorld\",\"BirthDate\":\"2020-03-03\",\"BirthPlace\":\"Nowhere\"}"
}
I required above format to post to web service but my code below doesn't fulfil the format. Please help. I've been using below code to post
var Data = JsonConvert.SerializeObject(new
{
Data = new
{
Name= "HelloWorld",
BirthDate = "2020-03-03",
BirthPlace= "Nowhere"
}
});
using (var client = new HttpClient())
{
HttpResponseMessage response = await client.PostAsJsonAsync(apiUrl, Data);
}
{"Data":{"Name":"HelloWorld","BirthDate":"2020-03-03","BirthPlace":"Nowhere"}}using (var client = new HttpClient())is just for the example, right? You shouldn't use it that way in production code.var Data = Newtonsoft.Json.JsonConvert.SerializeObject( new { Data = Newtonsoft.Json.JsonConvert.SerializeObject(new { Name = "HelloWorld", BirthDate = "2020-03-03", BirthPlace = "Nowhere" }) });