我正在尝试以 JSON 格式发送 http post 请求,该请求应如下所示:
{
"id":"72832",
"name":"John"
}
Run Code Online (Sandbox Code Playgroud)
我尝试像下面那样执行此操作,但如果我是正确的,这不会以 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
}
Run Code Online (Sandbox Code Playgroud)
如何修改代码以json格式发送请求?