How to get Access Token from ASP.Net Web API 2 via AngularJS $http?

前端 未结 6 1921
孤街浪徒
孤街浪徒 2021-02-04 02:12

I try like this:

$http({ method: \'POST\', url: \'/token\', data: { username: $scope.username, password: $scope.password, grant_type: \'password\' } }).success(f         


        
6条回答
  •  庸人自扰
    2021-02-04 02:58

    You are getting that error because the default implementation of the OWIN OAuth provider is expecting the post to the "/Token" service to be form encoded and not json encoded. There is a more detailed answer here How do you set katana-project to allow token requests in json format?

    But you can still use AngularJs you just have to change the way the $http post is made. You can try the answer here if you don't mind using jquery to change your params How can I post data as form data instead of a request payload? Hope that helps.

提交回复
热议问题