Reputation: 2730
I want to create a header for a http get request which should have following key and value
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
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
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