ionic-framework - 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.
解决方案
首先,检查您的外部 API 是否具有 SSL 保护意味着它是 Https 而不是 Http。如果它是 Https 并且您仍然收到错误,则使用下面的插件而不是 fetch() 或 Angular HttpClient。 https://ionicframework.com/docs/native/http
推荐阅读
- next.js - 下一个js链接不加载页面
- ios - 添加新类别时的百分比重新计算
- javascript - 基于 HTML5/NodeJS 的实时音频流
- time - 对计算机使用 for 循环是否比重复指令更快?
- java - Kafka poll 和 max.poll.interval.ms - 批处理最佳实践
- python - 读取并合并具有不同列的多个 csv 文件
- sql - Aggregate expression issue with GROUPBY
- jquery - 从signalR动态加载的Jquery数据表
- c# - EF6 包括实体中集合的引用
- entity-framework - 扩展自动生成的招摇文档以包含特定的端点?