I am currently utilizing the httpClient Angular package to make GET requests. The URL I am using to fetch data is , but I am encountering a CORS error in the console.
Unfortunately, I do not have access to the server side code, but I still want to enable CORS in my Angular service. Here is the function I am using:
myfunction() {
let head = new HttpHeaders();
head.append('Access-Control-Allow-Headers', 'Content-Type');
head.append('Access-Control-Allow-Methods', 'GET');
head.append('Access-Control-Allow-Origin', '*');
return this.http.get("https://api.independentreserve.com/Public/GetValidPrimaryCurrencyCodes", {headers: head}).toPromise();
}
I experimented with the Chrome CORS extension and it worked fine. However, I would prefer to have CORS enabled within my Angular code.
I also attempted to implement proxies by following this tutorial. Nevertheless, it did not solve the issue. Below is the content of my proxy.conf.json file:
{
"/api": {
"target": "https://www.independentreserve.com/Public/GetValidPrimaryCurrencyCodes",
"secure": false,
"changeOrigin": true
}
}
I added "start": "ng serve --proxy-config proxy.conf.json" to the package.json file, but this approach also failed to work. Does anyone have a solution for this problem?