我正在使用 AppGyver Steroids 和 AngularJS 开发一个混合移动应用程序。在这个移动应用程序中,我需要使用我开发的另一个项目的 RESTful API;这是我从移动应用程序发送的示例请求:
var data = {
'email': $scope.userEmail,
'password': $scope.userPassword
}
$http.post('http://example.com/api-auth-token/?format=json', data)
.success(function(data, status, headers, config) {
alert(data);
$location.path('/profile');
})
.error(function(data, status, headers, config) {
// show error details
navigator.notification.alert(
'Authentication failed. (' + status + ')',
null,
'Error',
'Okay'
);
});
这个请求很好地到达了服务器,并生成了一个状态码为 200 的有效响应......至少在我检查服务器日志时是这种情况。移动应用程序显示一个消息框,显示“身份验证失败。(404)' 这与服务器日志中的说明相矛盾。
编辑:我还开发了一个使用这些 API 的原生 iOS 应用程序,它可以正常工作。