I have one api calling another.
and here is my code which seems to cause ModelState.IsValid = false on the other side of world.
var baseUri = new Uri("http://localhost:5001/"):
_httpClient.BaseAdress = baseUri;
var data = new StringContent(content: model.Tostring(),
encoding: Encoding.UTF8,
mediaType: "application/json");
var response = await _httpClient.PostAsync("api/product", data);
watching Post([FromBody]Product product) on the api being called I just see product=null.
changing to Post([FromBody]object product) also shows null.
calling the api from Postman works perfectly fine. which localize my problem to PostAsync. what's going on with my PostAsync?
Edit:
I know people might suggest PostAsJsonAsync, but I'll try it only after I know what's the problem with PostAsync. :(
model.ToString()produces proper JSON? And even if it is, you'd better at least use a separate method likeToJsonStringor even don't put the serialization code inside that class at all.model.ToString()was not doing what I thought it's doing. changing tocontent: JsonConvert.SerializeObject(model)works. is that a way to go?