小编Gaz*_*991的帖子

在http post请求中发送JSON数据C#

我正在尝试以 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格式发送请求?

c# post json httprequest

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

httprequest ×1

json ×1

post ×1