I have an application on the server, I am very sure that I have CORS enabled in this application since I have an AngularJs client (1.x) and it works perfectly.
but, now I'm migrating to Angular 4 and I get the following error.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at ||my-url||. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)
I have read many questions here and they all say that it is a problem in server-side but as I said my server works well and has CORS enabled, my problem is specifically in the client
EDITED
I have tried this in my service.ts
createAuthorizationHeader(): RequestOptions {
// Just checking is this._options is null using lodash
if (isNull(this._options)) {
const headers = new Headers();
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
headers.append('Content-Type', 'application/json; charset=utf-8');
this._options = new RequestOptions({headers: headers});
}
return this._options;
}
getStudies(): Observable<any> {
const options = this.createAuthorizationHeader();
return this._httpService.get(this.WEB_API_URL, options)
.map((response: Response) => console.log(response.json()))
}
NEW EDIT
it seems that it has not yet been clear I have an angular application 1.x running on the same server as this new application in angular 4, THE BACKEND HAS CORS WELL CONFIGURED, IT IS BECAUSE THE OTHER APPLICATION ANGULAR 1 WORKS AND BEFORE WORKING I HAD TO CHANGE SOME PARAMETERS IN THE CLIENT I need to know how to do the same in angular 4