2

I have some concerns(marigolds) with my method GET when I send my request. I have received an error 401 and I am disconnected from the application, knowing that the token which I obtain in the console is very valid when I test on postman. I does not really understand(include) why that does not work I have to add some things or I have pain make something.

var list = function(){
    var mytoken = window.localStorage.getItem('token');
    return $http({
            method  : 'GET',
            url     : apiEndpoint.url + '/list',
            withCredentials : true,
            headers : {Authorization : 'Bearer ' + mytoken}
        }).then(function(res) {
        console.log(res.data);
    });
}; 

If somebody could me helped please, thank you :)

Elangovan
  • 3,469
  • 4
  • 31
  • 38
Lydia Ra
  • 155
  • 12
  • I haven't had to wrap my token in curly brackets before. What is the reason? – Ronnie Mar 25 '17 at 20:51
  • It was just a test to have the same result as on Postman .. but that I remove the brackets or not it is always the same result, 401 .. – Lydia Ra Mar 25 '17 at 21:03
  • When you have broken code, don't break it more and then post **double broken code**. Please edit your answer to show your best attempt. – georgeawg Mar 25 '17 at 21:37

2 Answers2

1

I think that she uses of the angularJS in her project, while RequestOptions is a class which we find that in Angular 2. That's why the import does not work

It must be added in the conf of apache:

SetEnvIf Authorization. + HTTP_AUTHORIZATION = $ 0

It should work for your case :)

Elangovan
  • 3,469
  • 4
  • 31
  • 38
DaxDev
  • 651
  • 6
  • 13
0

Please check it like below:

        let headers = new Headers();
    headers.append('Authorization', 'Bearer ' + YourToken);

    let options = new RequestOptions({ headers: headers });

    this.http.get('YourUrl', options)

This should work

Marcin.ka
  • 87
  • 2
  • 9