restAngular使用方法customPOST。 text:[object%20Object]被添加到URL的末尾

时间:2013-11-05 20:46:19

标签: angularjs restangular

我想要完成的目标是在restAngular中做一个帖子。我一直在尝试下面的代码,但是我收到了一个带有customPost的状态代码400。这是我发送请求的URL ... http://localhost/api/api/index.php/auth/token/ [object%20Object]。正如您所看到的,[object%20Object]正在添加gettting。我怎么摆脱这个?我应该在customPOST之外做另一种方法吗?为什么会加入这个?

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

1 个答案:

答案 0 :(得分:8)

customPOST的第二个参数应该是表示路径的字符串。试试这个:

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

或者这个:

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