Skip to content

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

@runtop

Description

@runtop

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions