I am using HTTPClient Module of Angular 4 for retrieving data from a database. The corresponding service has the following method,
getPosts() {
const httpHeaders = new HttpHeaders().set('Content-Type', 'application/json');
// tslint:disable-next-line:max-line-length
httpHeaders.set('Authorization for JWT', 'Token');
return this.http.get('http://localhost:9090/api/user' + '?user_id=' + this.user.id.toString(),
{headers: httpHeaders,
responseType: 'json'});
}
I am calling this method from a component as follows,
this.Servie.getPosts().subscribe(pos => {
console.log(pos);
});
But I am getting an error as follows in server side,
java.lang.RuntimeException: JWT Token is missing
error at the client side,
Failed to load http://localhost:9090/api/user?user_id=1: Response for preflight has invalid HTTP status code 500.
Please correct me where I am going wrong?
I Have made changes according to discussion below, but still problem is there as follows,
I think I have messed it up right now, I made the following changes as follows,
This is the code written in service,
const httpHeaders = new HttpHeaders()
.set('Content-Type', 'application/json')
// tslint:disable-next-line:max-line-length
.set('RequestAuthorization', 'Bearer ' + 'eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI5ODg0NjUxMjMzIiwidXNlcklkIjoiNSJ9.gwiZcx5I8rInXJGANvS9twupXjdjrzFdZNZ0K85u-KA8LXXDgDf27mUzUoiEyxRMg');
return this.http.get('http://localhost:9090/user' + '?user_id=' + this.user.id.toString(),
{headers: httpHeaders});
And i am calling the above service as follows,
this.userServie.getPosts().map((res: Response) =>
console.log(res.text()));
But the service is not hitting, i am not seeing the GET method in network tab of browser development tools. Where i am wrong ? Please correct me.