最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - cURL call in AngularJS using $http - Stack Overflow

programmeradmin3浏览0评论

I am new to angular and I'm trying to pass an access token in my header, but I cant seem to get it right.

I have a curl request that works fine and I'm trying to get it in working in angular:

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

Angular $http call that isn't working

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

Thanks!

I am new to angular and I'm trying to pass an access token in my header, but I cant seem to get it right.

I have a curl request that works fine and I'm trying to get it in working in angular:

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

Angular $http call that isn't working

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

Thanks!

Share Improve this question asked Nov 6, 2014 at 0:10 bobcobbbobcobb 1491 gold badge5 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

Based on your curl I think the request should look like:

$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);
    });
发布评论

评论列表(0)

  1. 暂无评论