Javascript Angularjs http请求

Javascript Angularjs http请求,javascript,angularjs,api,oauth,Javascript,Angularjs,Api,Oauth,我试着用angularjs申请 POST /api/oauth/token HTTP/1.1 Host: Myweb.com Authorization: Basic Base64(client_id:client_secret) Content-Type: application/x-www-form-urlencoded grant_type=client_credentials 像这样 Var req = { method: 'POST', url: 'http

我试着用angularjs申请

 POST /api/oauth/token HTTP/1.1
 Host: Myweb.com
 Authorization: Basic Base64(client_id:client_secret)
 Content-Type: application/x-www-form-urlencoded

 grant_type=client_credentials
像这样

 Var req = {
   method: 'POST',
   url: 'https://Myweb.com/api/oauth/token',
   headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Authorization': 'basic YjBiZGNkZTQtNmE5OS00ZDE4LTg5ZWQtYasdYtek0MzkTWCXy1LTRmOTktNDk0MS1iNDY2LTc2NDysdYdfsdxMzFiYg=='              
   },
   data: { 
           'grant_type':'client_credentials'                
         }     
 }

 $http(req).then(function successCallback(response) {
              console.log('Success');
            }, function errorCallback(response) {
              console.log('Failed');
            });
结果总是失败,如何正确地应用到grant_类型部分??
请帮助我

请参考这段代码

var _login = function (loginData) {

        var data = "grant_type=password&username=" + 
        loginData.userName + "&password=" + loginData.password;

        var deferred = $q.defer();

        $http.post(serviceBase + 'token', data, { headers: 
        { 'Content-Type': 'application/x-www-form-urlencoded' } }).success(function (response) {

            localStorageService.set('authorizationData', 
            { token: response.access_token, userName: loginData.userName });

            _authentication.isAuth = true;
            _authentication.userName = loginData.userName;

            deferred.resolve(response);

        }).error(function (err, status) {
            _logOut();
            deferred.reject(err);
        });

        return deferred.promise; 
    };
它实际上是从 请尝试以下代码:

   var url="https://Myweb.com/api/oauth/token";    
    var data={ 
               'grant_type':'client_credentials'                
             };  

    $http.post(url,data,{ 
      headers:{
                'Content-Type': 'application/x-www-form-urlencoded',
                'Authorization': 'basic YjBiZGNkZTQtNmE5OS00ZDE4LTg5ZWQtYasdYtek0MzkTWCXy1LTRmOTktNDk0MS1iNDY2LTc2NDysdYdfsdxMzFiYg=='              
       }
    })
   .then(function(success){

   },function(failure){

   });

你会犯什么错误?这是一个JS错误,还是一个服务器错误?没有JS或服务器错误,我得到了失败的响应。如何应用以获取数据?触发哪个回调,成功还是错误回调?我获取错误回调