aspnet / AspNetWebStack

ASP.NET MVC 5.x, Web API 2.x, and Web Pages 3.x (not ASP.NET Core)
Other
858 stars 354 forks source link

HttpClient ‘s PostAsJsonAsync is not work correctly in netcore3.1 with standalone deploy #274

Closed runtop closed 4 years ago

runtop commented 4 years ago

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?

odin88 commented 4 years ago

Is this asp.net core application or asp mvc 5.x ?

mkArtakMSFT commented 4 years ago

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.