I attempted to send a request with an authorization header using Angular's HttpClient but the header was not set successfully.
Here my code.
import {HttpClient, HttpHeaders} from '@angular/common/http';
constructor(private http: HttpClient,
private auth: AuthService) {
}
sendRequest() {
this.http.get(this.url, {
headers: new HttpHeaders().set('Authorization', 'Bearer ' + this.auth.getAccessToken())
}).subscribe(
data => {
console.log(data);
},
error => {
console.log(error);
}
);
}
And here the network debug header source.
OPTIONS /userinfo HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Access-Control-Request-Method: GET
Origin: http://localhost:4200
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36
Access-Control-Request-Headers: authorization
Accept: */*
Referer: http://localhost:4200/user
Accept-Encoding: gzip, deflate, br
Accept-Language: ja,en-US;q=0.8,en;q=0.6
The response header is as follows.
HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Sun, 27 Aug 2017 23:45:15 GMT
Content-Length: 18
Is there something wrong?