Closed runtop closed 4 years ago
Is this asp.net core application or asp mvc 5.x ?
Thanks for contacting us. It's not clear how to reproduce this issue. We suggest reviewing the new System.Text.Json.Http extension methods and see whether that helps with your problem.
here is the code :
HttpClient client = new HttpClient();
client.PostAsJsonAsync(url, some object);
These code can work correctly in dev environment netcore3.1 using vs2019. it can send json object data to the server, But when deployed to iis with stand alone mode (already deploy with System.Net.Http.Formatting.dll), the httpclient can not send json object to the same server. There has no error occur, just only the server received a null object data. Then I change these code to next :
first defined a new class
public class JsonContent : StringContent {
public JsonContent(object obj) :
base(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json") { } }
then
client.PostAsync(url, new JsonContent(data));
and it works correctly.
How can i do wit PostAsJsonAsync correctly?