7π
β
.NET isnβt seeing you passing a string, it sees a JSON because you pass the Content-Type
header of application/json
so it will try to deserialize it and map it to your request object. In your case, because your parameter is string body
the parser tries to map the JSON object to your string
and fails β so it passes null
.
You can try and change the request to pass text/plain
as the content-type
(or remove the content-type
header) or change your API parameter to the object you are sending:
public IActionResult AddNewProduct([FromBody] Product newProduct)
{
...
}
π€Simply Ged
2π
Add to headers Accept
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
π€Sith2021
Source:stackexchange.com