我可以將數據發送到服務器,但僅在使用FromBody-Attribute時。爲什麼我需要FromBody屬性期待POST主體中的數據
爲什麼json數據不能自動從郵件正文中讀取?
後端Web API
[HttpPost]
public async Task<IActionResult> Post([FromBody]CreateSchoolyearRequestDTO dto)
{
}
前端angularjs
this.createSchoolyear = function (schoolyear) {
var path = "/api/schoolyears";
return $http({
url: path,
method: "POST",
data: schoolyear,
contentType: "application/json"
}).then(function (response) {
return response;
});
};
因爲您發送POST數據作爲有效載荷(在POST體)注入 – dfsq