【发布时间】:2013-12-04 13:31:37
【问题描述】:
我尝试这样:
$http({ method: 'POST', url: '/token', data: { username: $scope.username, password: $scope.password, grant_type: 'password' } }).success(function (data, status, headers, config) {
$scope.output = data;
}).error(function (data, status, headers, config) {
$scope.output = data;
});
然后尝试将 grant_type 更改为参数:
$http({ method: 'POST', url: '/token', data: { username: $scope.username, password: $scope.password }, params: { grant_type: 'password' } }).success(function (data, status, headers, config) {
$scope.output = data;
}).error(function (data, status, headers, config) {
$scope.output = data;
});
仍然感到恐惧:{"error":"unsupported_grant_type"}
所以我做了 AngularJS 开发者不应该做的事,求助于 jQuery:
var data = $('#regForm').serialize() + "&grant_type=password";
$.post('/token', data).always(showResponse);
function showResponse(object) {
$scope.output = JSON.stringify(object, null, 4);
$scope.$apply();
};
这就像一个冠军......所以我的问题是:我们如何使用 AngularJS $http() 复制上面的 jQuery $.post() 调用,以便我们可以从 ASP 中基于 OWIN 中间件的 /token 端点获取访问令牌。网络 Web API 2?
【问题讨论】:
-
你的问题在这个answer解决了
标签: javascript jquery angularjs asp.net-web-api asp.net-web-api2