前端:
return this.http.post(
'/api/products',
JSON.stringify(params),
{headers: new HttpHeaders({'Content-Type': "application/x-www-form-urlencoded;charset=UTF-8"})
}
).pipe(map(res => res))
服务端:
request.body为undefined
看浏览器的network:
form data:
{"title":"","price":null,"category":"-1"}:
将 application/x-www-form-urlencoded;charset=UTF-8
改为 application/json; charset=utf-8
不要使用stringify。然后去掉第三个参数。