我试图实现的目标是在restAngular中发表文章。我继续尝试下面的代码,但是收到带有customPost的状态代码400。这是我将请求发送至... http://localhost/api/api/api/index.php/auth/token/ [object%20Object]的URL。如您所见,[object%20Object]正在添加。我该如何摆脱呢?除customPOST之外,我还应该做其他方法吗?为什么要增加它?

  var login = Restangular.one('auth/token').customPOST(
    {grant_type:"password", username:"[email protected]",password:"666666",scope:"app"},{},{},
    {Authorization:'Basic ' + client,
    ContentType:'application/x-www-form-urlencoded'});

最佳答案

customPOST的第二个参数应该是代表路径的字符串。尝试以下方法:

var login = Restangular.one('auth/token').customPOST(
    {grant_type:'password', username:'[email protected]', password:'666666', scope:'app'},
    '',
    {},
    {
        Authorization:'Basic ' + client,
        ContentType:'application/x-www-form-urlencoded'
    }
);


或这个:

var login = Restangular.one('auth').customPOST(
    {grant_type:'password', username:'[email protected]', password:'666666', scope:'app'},
    'token',
    {},
    {
        Authorization:'Basic ' + client,
        ContentType:'application/x-www-form-urlencoded'
    }
);

09-28 13:08