I am using django rest framework as backend and trying to authenticate request in angular using token in request headers but angular is not sending any header values. I have tried all methods of adding headers to request
test(){
//var headers = new HttpHeaders();
//headers.append('Authorization',':Token '+ token);
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/
Access-Control-Allow-Origin
andAccess-Control-Allow-Headers
headers. Your server should be returning these upon anOPTIONS
or on anyGET
. Other then that, could you post the actual response from the server your Angular app is retrieving? It seems like you have gotten the CORS headers the wrong way around. – Bjorn 'Bjeaurn' SAuthorization
header. Your server logs will probably say similar. – Bjorn 'Bjeaurn' S