あなたがionic serve
commnadを使用している場合、あなたはプリフライトとCORSの問題を防ぐためにプロキシを使用している必要があり、
まず
{
"name": "APP-NAME",
"app_id": "",
"proxies": [
{
"path": "/api",
"proxyUrl": "http://example.com/api"
}
]
}
よう
ionic.config.json
ファイルにAPIのパスとURLを追加
http
からAPIを呼び出す際に、http://example.com/api
の代わりに/api
のURLを使用します。
....
this.http.post('/api', data, {headers:headers}).map(res=>res.json()).subscribe(data=>{
console.log(data)
}, err=>{
console.log("Error!:", err.json());
});
....
上記の変更を加えたら、コマンドionic serve
を再実行する必要があります。
はまだ、あなたが問題を取得している場合、実際にHandling CORS Issues In Ionicとhttps://ionicframework.com/docs/cli/configuring.html