0

this is my client code

var client = new HttpClient();
            client.BaseAddress = new Uri(BASE_URL);
            var multipart = new MultipartFormDataContent();
            var jsonToSend = JsonConvert.SerializeObject(template, Formatting.None);
            var body = new StringContent(jsonToSend, Encoding.UTF8, "application/json");
            multipart.Add(body, "JsonDetails");
            return client.PostAsync("jsons", multipart);

server code is

 [HttpPost("jsons")]
        public async Task<IActionResult> RequestJson([FromBody]Person person)
        {

        if (person != null)
        {
            return Ok("true");
        }


        return Ok("false");

person code

public class Person
    {
        public string Name { get; set; }
        public string Position { get; set; }
    }

when look in debug my post from client dont knock to server, in postman my post sending and i can see my object property

1 Answer 1

3

Just post the StringContent directly without the Multipart-Form:

var client = new HttpClient
{
    BaseAddress = new Uri(BASE_URL)
};

var jsonToSend = JsonConvert.SerializeObject(template, Newtonsoft.Json.Formatting.None);

var body = new StringContent(jsonToSend, Encoding.UTF8, "application/json");

return client.PostAsync("jsons", body)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.