I'm facing some problems to perform a HTTP get operation with a server, within my Ionic 4 application. This is the method that I use to perform the HTTP request:
getRank(){
let headers = { headers: this.authenticationService.getHeadersToken(), withCredentials : true};
return this.http.get<RankRowsResponse>(this.env.API_URL + 'classificajson.php', headers);
}
And the method that returns the headers token is:
getHeadersToken(){
var headers = new HttpHeaders();
headers.append('Access-Control-Allow-Origin' , '*');
headers.append('Access-Control-Allow-Credentials', "true");
headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT');
headers.append('Accept','application/json');
headers.append('Content-Type','application/json');
console.log('PHPSESSID='+this.token.toString());
headers.append('cookie','PHPSESSID='+this.token.toString());
return headers;
}
When I call the method getRank() Google Chrome prints out this error:
Access to XMLHttpRequest at 'https://www.fantacalciopizza.it/php/classificajson.php' from origin 'http://localhost:8102' has been blocked by CORS policy
I've installed a Chrome Extensions for CORS but the error is still present; how Can I do? Where am I wrong with the request?