No header "Access-Control-Allow-Origin" is present on Ionic2 mail request

This is my complete code ...

this.http.post(link, data, { headers: headers }) .map(res => res.json()) .subscribe(data => { this.data.response = data._body; }, error => { console.log("Oooops!"); }); 

after running the code, this error is present:

 "XMLHttpRequest cannot load https://script.google.com/macros/s/AKfycbzdHHKBmLWJYZtFGlJGOrUwlPIWXor1geEOgcSgvhs/dev. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access. The response had HTTP status code 401." 

I was looking for CORS ... but I can't get around it ...

Any help would be appreciated.

+1
source share
2 answers

I have the same problem, but a few hours later, to find my problem, I left.

ionic.config.json

 { "name": "KickStarter", "app_id": "85ff0666", "v2": true, "typescript": true, "proxies": [ { "path": "/mobile", "proxyUrl": "http://xxxxx:port/mobile" } ] } 

you must use ionic g provider [name-of-provider] --ts , it will generate the provider to make the request as follows:

 export class AuthProvider { data: any = null; constructor(public http: Http) { } load() { if (this.data) { // already loaded data return Promise.resolve(this.data); } // don't have the data yet return new Promise(resolve => { // We're using Angular Http provider to request the data, // then on the response it'll map the JSON data to a parsed JS object. // Next we process the data and resolve the promise wi new data. this.http.get('/mobile/api/authentication') .map(res => res.json()) .subscribe(data => { // we've got back the raw data, now generate the core schedule data // and save the data for later reference resolve(this.data); }); }); } } 

just remember: /mobile/api/authentication β†’ /mobile from path in ionic.config.json .

+2
source

Download the Allow-Control-Allow-Origin app from Google Chrome. Turn on CORS in the installed program and execute your code. This will temporarily enable CORS in your browser.

-3
source

Source: https://habr.com/ru/post/1247082/


All Articles