下面通過我的角度和網絡API Code.In POST方法將null獲得通過,而不是印度 角代碼:參數沒有得到從角度對Web API中的POST調用
HWApp.controller('TestCtrl', function ($scope, $http) {
$scope.SendData = function (Data)
{
$scope.whoo = Data;
console.log(Data);
$http({
url: "api/call/firstCall",
dataType: 'json',
method: 'POST',
data: "India",
headers: {
"Content-Type": "application/json"
}
}).success(function (response) {
$scope.whoo = response;
})
.error(function (error) {
alert(error);
});
}
}
);
網絡API控制器
public class CallController : ApiController
{
[HttpGet]
public string firstCallGet()
{
return "Get";
}
[HttpPost]
public string firstCall([FromBody] string a)
{
return a;
}
}
看到這個http://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-數據 – mindparse
我也試過這個數據:{data:'India'}但是相同的null正在通過。 –
看看是否有幫助:http://stackoverflow.com/questions/30957248/how-to-send-post-in-angularjs-with-multiple-params/30957308#30957308 – Sajal