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 :)

3
  • I haven't had to wrap my token in curly brackets before. What is the reason? Commented Mar 25, 2017 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 .. Commented Mar 25, 2017 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. Commented Mar 25, 2017 at 21:37

2 Answers 2

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 :)

Sign up to request clarification or add additional context in comments.

Comments

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

4 Comments

Thank you for your answer :) I get the following error: RequestOptions is not defined Unfortunately I am a noob yet on angularjs of the blow I do not know where to add "import"
do You use TypeScript?
Hum nop, I have not used TypeScript so far
I put import {RequestOptions} from '@ angular / http'; In the app.component.ts file but still the same error RequestOptions is not defined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.