首页 > 解决方案 > CORS issue when running ionic project on android and browser

问题描述

I am having an ionic 3 project which is accessing remote url. However when i run the project on browser with "ionic serve" or on android emulator/device using "ionic cordova build android" command I am getting this following error :

Fetch API cannot load API URL. Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. Origin 'http://localhost:8080' is therefore not allowed access.

I googled and found that this is CORS issue which occurs when one domain tries to access other domain, but the project works properly on other 2 machine on same network. The database in use is couchDB.

标签: ionic-frameworkionic3couchdb

解决方案


首先,检查您的外部 API 是否具有 SSL 保护意味着它是 Https 而不是 Http。如果它是 Https 并且您仍然收到错误,则使用下面的插件而不是 fetch() 或 Angular HttpClient。 https://ionicframework.com/docs/native/http


推荐阅读