[英]Ionic Backand App refused connection to server on Android Device, not on emulator
I recently learned how to build a mobile application using Ionic and needed a backend so I decided to use the Backand framework. 我最近学习了如何使用Ionic构建移动应用程序,并且需要一个后端,因此我决定使用Backand框架。 I am developing in Visual Studio and everything works great when run from the emulator, and all service calls work perfectly, however when I attempt to perform the same service (POST) operations from an Android Device I get the following error. 我正在Visual Studio中进行开发,并且从模拟器运行时一切正常,并且所有服务调用均正常运行,但是当我尝试从Android设备执行相同的服务(POST)操作时,出现以下错误。
Refused to connect to 'https: //api.backand.com/1/objects/player/'; 拒绝连接到'https://api.backand.com/1/objects/player/'; because it violates the following Content Security Policy directive: "default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval 因为它违反了以下“内容安全策略”指令:“ default-src'self'数据:gap: https ://ssl.gstatic.com'unsafe-eval
I found a similar issue in which the solution was that I may need to reference the servers address in index.html 's meta tag 我发现了一个类似的问题,解决方案是我可能需要在index.html的meta标记中引用服务器地址。
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https: //ssl.gstatic.com 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src https://api.backand.com:*">
This however crashes the application and now I have hit a dead end as to where I should go from here. 但是,这使应用程序崩溃了,现在我该死了。 I would be happy to provide any more information that may be necessary, any help would be greatly appreciated! 我很乐意提供更多必要的信息,我们将不胜感激!
Thanks 谢谢
This is a guide on Cordova's whitelist and CSP policy: http://taco.visualstudio.com/en-us/docs/cordova-security-whitlists/ . 这是有关Cordova白名单和CSP政策的指南: http : //taco.visualstudio.com/en-us/docs/cordova-security-whitlists/ 。 If you have further problems with this scenario, please email vscordovatools@microsoft.com with your questions. 如果您在这种情况下还有其他问题,请向您发送问题的电子邮件至vscordovatools@microsoft.com。
Disclosure: I work on the Cordova team at MSFT 披露:我在MSFT的Cordova团队工作
ensure you add cordova-whitelist-plugin after you add android platform to your application. 将Android平台添加到应用程序后,请确保添加cordova-whitelist-plugin。
Order of commands have to be: 命令顺序必须为:
ionic platform add android
and after it 然后
cordova plugin add cordova-plugin-inappbrowser
ionic plugin add https://github.com/apache/cordova-plugin-whitelist.git
if you change the order, ionic will install plugin only for current platform that is ios. 如果您更改顺序,ionic将仅针对当前平台(即ios)安装插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.