Thursday, 24 November 2016
typescript - Enable Access-Control-Allow-Origin in angular 5 from Client side
Answer
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?
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
A fair amount of the second act of The Dark Knight Rises has a class warfare plotline. This is foreshadowed in the trailers with Selina Ky...
-
How can I detect either numbers or letters in a string? I am aware you use the ASCII codes, but what functions take advantage of the...
-
I want to create an options array from a string. How can i create an array as { width : 100, height : 200 } from a string ...
No comments:
Post a Comment