【问题标题】:restAngular using method customPOST. text:[object%20Object] is getting added on to the end of URLrestAngular 使用方法 customPOST。文本:[object%20Object] 被添加到 URL 的末尾
【发布时间】:2013-11-06 08:25:31
【问题描述】:

我想要实现的目标是在 restAngular 中发帖。我一直在尝试下面的代码,但我收到一个带有 customPost 的状态代码 400。这是我将请求发送到的 URL...http://localhost/api/api/index.php/auth/token/[object%20Object]。如您所见,[object%20Object] 正在添加。我该如何摆脱这个?除了 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'});

【问题讨论】:

    标签: angularjs restangular


    【解决方案1】:

    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'
        }
    );
    

    【讨论】:

    • 仍然获得 400,但至少我们更近了一步。谢谢。
    • 我必须将有效负载 JSON 包装在对 JQuery 的 $.param({}) 的调用中以对其进行参数化。一旦我这样做了,404 错误就消失了。
    • 如果有人发现它不起作用,我不得不将ContentType:'application/x-www-form-urlencoded' 更改为'Content-Type':'application/x-www-form-urlencoded'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 2017-06-15
    • 2013-08-07
    相关资源
    最近更新 更多