Using Django REST framework for the backend, I am attempting to authenticate requests in Angular by including a token in the request headers. However, Angular does not seem to be sending any header values. Despite trying various methods to add headers to the request.
test(){
let token='Token '+'d7dd1e453bae5086e33243b9adca5b63d2d927fb8';
const httpOptions = {
headers: new HttpHeaders({
'Authorization':'Token d7dd1e453bae5086e33243b9adca5b63d2d927fb8',
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':'X-Requested-With'
})
};
console.log(token);
this.http.get('http://localhost:8003/hello/', httpOptions).subscribe(
response=>{console.log(response);}
);
}
Access-Control-Request-Headers: access-control-allow-headers,access-control-allow-origin,authorization,content-type Access-Control-Request-Method: GET DNT: 1 Origin: http://localhost:4001 Referer: http://localhost:4001/