我得到什麼,我認爲是在iPhone模擬器版本CORS問題SimulatorApp-829.6 /的Xcode 9.0離子3在iPhone模擬器CORS問題
我建立了一個ionic3應用瓦特/科爾多瓦,並且可以在運行瀏覽器使用代理。但是,當我在SIM或手機上運行它時,它不會針對遠程http呼叫進行身份驗證。
所以我添加科爾多瓦調試器和調試的Xcode的控制檯:
這是HTTP錯誤對象:
{"_body":{"isTrusted":true},"status":0,"ok":false,"statusText":"","headers":{},"type":3,"url":null}
這是我在離子應用程序執行代碼(在瀏覽器中的作品)
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Basic ' + this.base64Service.encode(id + ':' + pw));
headers.append('Access-Control-Allow-Origin', '*');
return this.http.get('http://myserver.com/api/v1/authenticate', {headers: headers}).map(res => res.json());
我真的很困惑,因爲兩件事情:
1)我已經安裝了科爾多瓦白名單的插件和之前已經成功對遠程服務器。不知道這是怎麼回事
2)如果我使用Safari開發>模擬器,並連接到在模擬器中運行的應用程序也給出了這樣的錯誤:
Failed to load resource: Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin.
XMLHttpRequest cannot load http://myserver.com/api/v1/authenticate. Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin.
你怎麼可以在SIM獲得CORS問題或實際設備?我認爲這些資源都是基於file://的。另外,爲什麼Cordova白名單插件不能解決這個問題?
在此先感謝。已經花了很多時間在這個。