Wednesday, January 31, 2018

typescript - Enable Access-Control-Allow-Origin in angular 5 from Client side

I am using httpClient angular package for get requests. I am using https://api.independentreserve.com/Public/GetValidPrimaryCurrencyCodes url for fetching data. It is giving CORS error in console.



I don't have access to server side code, but still I want to enalbe CORS in angular service. This is my service function




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 have tried it with chrome cors extension, and it works fine. But I want this to be enabled from angular code.




I have also tried working with proxies, following tutorial. BUt it is still not working. This is my object in proxy.conf.json file.



{
"/api": {
"target": "https://www.independentreserve.com/Public/GetValidPrimaryCurrencyCodes",
"secure": false
},
"changeOrigin": true
}



and added "start": "ng serve --proxy-config proxy.conf.json" in package.json file. It is not working this way either.



Can any body give me some solution?

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...