我需要进行一个简单的WebAPI调用,使用字符串参数的POST方法。
以下是我尝试的代码,但当在WebAPI方法上设置断点时,接收到的值为
以下是我尝试的代码,但当在WebAPI方法上设置断点时,接收到的值为
null
。StringContent stringContent = new System.Net.Http.StringContent("{ \"firstName\": \"John\" }", System.Text.Encoding.UTF8, "application/json");
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.PostAsync(url.ToString(), stringContent);
和服务器端代码:
// POST api/values
[HttpPost]
public void Post([FromBody]string value)
{
}
please help...
"firstName" != "value"
- Preston Guillot