我是React Native中的新手,我想在React Antive Fetth到ASP.NET Web API中发布一个表单数据。但是它总是会收到。这是我的反应代码获取代码
let response = await fetch(`${apiConfig.url}${action}`, {
method: "POST",
headers: requestHeaders,
body: "userName=" + encodeURIComponent(body.UserName) +
"&password=" + encodeURIComponent(body.Password) + "&grant_type=password",
});
let responseJson = await response.json();
和Web API代码
[HttpPost]
public IHttpActionResult Save(Company company)
{
var result = _companyRepository.Create(company);
return Ok(result);
}
,但它总是接收公司对象null。我的小姐在哪里?请指出我。
尝试将 [来自Body] 属性添加到参数:
[HttpPost]
public IHttpActionResult Save([FromBody] Company company)
{
var result = _companyRepository.Create(company);
return Ok(result);
}