不同的Content-Type需要使用不同类型的请求体
application/x-www-form-urlencoded对应:
var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"name1","value1" },
{"name2","value2" }
});
application/form-data:
var content = new MultipartFormDataContent();
content.Add(new StringContent("小明"), "name");
content.Add(new StringContent("18"), "age");
application/json:
var response = await httpClient.PostAsync(
url,
new StringContent(
Newtonsoft.Json.JsonConvert.SerializeObject(new { Name = "小明", Id = 1 }),
Encoding.UTF8,
"application/json")
);