【问题标题】:cURL call in AngularJS using $http使用 $http 在 AngularJS 中进行 cURL 调用
【发布时间】:2015-01-02 09:01:21
【问题描述】:

我是 Angular 的新手,我正在尝试在我的标头中传递一个访问令牌,但我似乎无法正确处理。

我有一个可以正常工作的 curl 请求,我正在尝试让它在 Angular 中工作:

curl http://localhost:3000/api/v1/users -IH "Authorization: Token api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Angular $http 调用不起作用

$http.get('http://localhost:3000/api/v1/users', {headers: {'api_key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'}}).then(function(response) {
                service.currentUser = response.data.user;
                console.log(service.currentUser);

谢谢!

【问题讨论】:

    标签: javascript angularjs curl


    【解决方案1】:

    根据你的 curl 我认为请求应该是这样的:

    $http.get('http://localhost:3000/api/v1/users', 
        {headers: { Authorization: ' Token api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxx'}})
        .then(function(response) {
                service.currentUser = response.data.user;
                console.log(service.currentUser);
        });
    

    【讨论】:

    • 是的,很惊讶我错过了。谢谢!
    猜你喜欢
    • 2017-06-15
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    相关资源
    最近更新 更多