Shoaib Iqbal
Shoaib Iqbal

Reputation: 2730

Create header for http requests

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.

Upvotes: 0

Views: 669

Answers (2)

Mahammad Adil Azeem
Mahammad Adil Azeem

Reputation: 9392

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.

Upvotes: 0

CharanRoot
CharanRoot

Reputation: 6325

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

Upvotes: 2

Related Questions