简体   繁体   English

Ionic Backand App拒绝连接到Android设备上的服务器,而不是模拟器上的服务器

[英]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.

相关问题 Android应用程序与网站(服务器)的连接 - Android app and website(server) connection Xamarin 表单,在 Visual Studio Android 模拟器上运行的应用程序但在真实设备上崩溃 - Xamarin forms, App running on Visual Studio Android Emulator But crashes on real device xamarin android apk安装在模拟器上,但未安装在设备上 - xamarin android apk installs on emulator but not on device 使用Xamarin的Android模拟器无法打印设备日志 - Device Logs not printing for android emulator using Xamarin Visual Studio Android 模拟器没有互联网连接 - No internet connection for Visual Studio Android Emulator 无法在 Android 模拟器 VS 2019 中创建新设备 - Not able to create new device in Android emulator VS 2019 适用于Android的Visual Studio模拟器挂起安装设备配置文件 - Visual Studio Emulator for Android hangs installing device profile 没有Internet连接的Visual Studio Xamarin和Android模拟器 - Visual Studio Xamarin and Android emulator without internet connection 尝试从 android 应用程序登录到我的服务器时出现“无法建立 ssl 连接”或“SSL 握手中止” - Getting "The ssl connection could not be established" or "SSL handshake aborted" when trying to log in from android app to my server 模拟器的Azure连接错误 - Azure Connection Error with Emulator
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM