【发布时间】:2018-07-17 01:22:38
【问题描述】:
我只是想通过 AngularJS $http 将一些基本的表单数据传递给 web-api。
这是调用以将数据发送到 API 的函数:
$http({
url: "/Portal/GenerateTimeSheets",
method: "POST",
headers: {
'Content-Type': 'application/json'
},
data: angular.toJson($scope.placementForm),
}).then(function (response) {
}), function(response) {
};
注意:如果我断点并将 $scope.placementForm 数据复制并粘贴到邮递员中,它完全可以正常工作,但是通过浏览器会引发错误。
这是我的 api:
[HttpPost]
public void GenerateTimeSheets([FromBody]PlacementModel placement)
{
Console.WriteLine("STUB");
}
和放置模型:
[JsonProperty(PropertyName = "candidateName")]
public string CandidateName { get; set; }
[JsonProperty(PropertyName = "clientName")]
public string ClientName { get; set; }
[JsonProperty(PropertyName = "jobTitle")]
public string JobTitle { get; set; }
[JsonProperty(PropertyName = "placementStartDate")]
public string StartDate { get; set; }
[JsonProperty(PropertyName = "placementEndDate")]
public string EndDate { get; set; }
[JsonProperty(PropertyName = "frequency")]
public string TimeSheetFrequency { get; set; }
【问题讨论】:
-
404表示你请求的路径错误
-
路径是 100% 正确的,这就是为什么让我感到困惑 @Sajeetharan
-
那很奇怪,我可以看看网络标签的截图
-
如果可能,请发布邮递员中显示的请求数据和 devtools 网络选项卡中显示的请求数据。
-
开发工具中的请求是什么?很可能路径是错误的