0

I want to create a header for a http get request which should have following key and value

enter image description here

Currently I am doing this to achieve it:

let header= new Headers();
header.append('Authorization','Token '+this.auth.data.authtoken);

But it is 401 unauthorized response. But in postman it is working.

2
  • are you setting options? let options = new RequestOptions({ headers: headers }); then passing this as the third option of the post request Commented Jun 23, 2017 at 1:28
  • Look at my get file function and it's responce Commented Jun 23, 2017 at 1:44

2 Answers 2

2

you can add headers like

 let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('Authorization': api_token);

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

    return this.http
        .get(url, options);
Sign up to request clarification or add additional context in comments.

1 Comment

Have a look at my function and response in answer section
0

When setting Authorization header. Its pretty standard to have a space between auth token and the prefix.

let header= new Headers(); header.append('Authorization','Token ' + ' '+ this.auth.data.authtoken);

Also you need to append Content-type header.

Comments

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.