【发布时间】:2021-08-09 23:45:00
【问题描述】:
我正在尝试以 JSON 格式发送一个 http post 请求,应该如下所示:
{
"id":"72832",
"name":"John"
}
我已经尝试像下面那样做,但如果我是正确的,这不是以 json 格式发送请求。
var values = new Dictionary<string,string>
{
{"id","72832"},
{"name","John"}
};
using (HttpClient client = new HttpClient())
{
var content = new FormUrlEncodedContent(values);
HttpResponseMessage response = await client.PostAsync("https://myurl",content);
// code to do something with response
}
如何修改代码以json格式发送请求?
【问题讨论】:
标签: c# json post httprequest