android - Cordova 应用程序未在 Android 上调用 API - net::ERR_CONNECTION_REFUSED

标签 android cordova ember.js content-security-policy

我已经研究了很多类似的问题,但似乎没有一个对我有用。我们的应用程序发出 2 个 API 请求 - 第一个请求将 OAuth 代码获取到我们的 API(工作正常),其他请求将代码发送到 Rails API(失败)。

我正在发帖到http://localhost:3000/api/v1/users/auth/openid_connect/callback

但是得到net::ERR_CONNECTION_REFUSED 。但是,在 iOS 上运行时效果很好。

我的配置当前有:

<plugin name="cordova-plugin-whitelist" spec="1" />
<access origin="*" />
<allow-navigation href="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

我尝试添加 <allow-intent href="http://localhost:3000/api/v1/*" /><allow-intent href="http://127.0.0.1:3000/api/v1/*" />甚至完整的openid_connect/callback URL,但似乎都不起作用。

在我的index.html ,我有

<meta http-equiv="Content-Security-Policy" content="default-src * 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src * 'unsafe-inline'">

问题是否在于我的处理方式 access origin在配置中还是我有 Content-Security-Policy错了?

最佳答案

为了解决这个问题,错误是 Android 似乎不知道如何处理 localhost。将域名更改为 http://10.0.2.2 解决了问题。

关于android - Cordova 应用程序未在 Android 上调用 API - net::ERR_CONNECTION_REFUSED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42093055/

相关文章:

node.js - 错误! Windows_NT 6.3.9600,windows8无法安装cordova

iphone - 我们可以将 'phonegap api ' 应用程序与纯 native 应用程序(obj-C)代码连接起来吗

javascript - 如果条件为整数值,如何编写 Handlebars

node.js - Ember : The response to store. 查询应该是一个数组,但它是一条记录错误

javascript - Ember : store not available in Application. 初始值设定项

android - 我们如何创建一个圆柱形的viewpager?

java - 带有清除按钮的 Android java android.support.design.widget.TextInputLayout

Android连接到网络共享套接字

android - 带有自定义 View 的 ActionBar 选项卡未居中

java - Phonegap 中未显示 native android 菜单