简体   繁体   English

Cordova应用未在Android上达到API-net :: ERR_CONNECTION_REFUSED

[英]Cordova app not hitting API on Android - net::ERR_CONNECTION_REFUSED

I've looked through a lot of similar issues, but none have seemed to work for me. 我浏览了许多类似的问题,但似乎没有一个对我有用。 Our app makes 2 API requests - the first to fetch an OAuth code to our API (works fine) and the other posts that code to the Rails API (which is failing). 我们的应用程序发出了2个API请求-第一个请求将OAuth代码获取到我们的API(可以正常工作),其他帖子则将其编码到Rails API(失败)。

I am posting to http://localhost:3000/api/v1/users/auth/openid_connect/callback 我正在发布到http://localhost:3000/api/v1/users/auth/openid_connect/callback

But getting net::ERR_CONNECTION_REFUSED . 但是得到net::ERR_CONNECTION_REFUSED However, this works fine when running on iOS. 但是,这在iOS上运行时效果很好。

My config currently has: 我的配置当前具有:

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

I've tried adding <allow-intent href="http://localhost:3000/api/v1/*" /> and <allow-intent href="http://127.0.0.1:3000/api/v1/*" /> and even the full openid_connect/callback URL but none seem to work. 我尝试添加<allow-intent href="http://localhost:3000/api/v1/*" /><allow-intent href="http://127.0.0.1:3000/api/v1/*" />甚至完整的openid_connect/callback URL,但似乎没有任何作用。

In my index.html , I have 在我的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'">

Does the issue lie with how I am handling access origin in the config or do I have the Content-Security-Policy wrong? 问题出在我如何处理配置中的access origin ,还是我的Content-Security-Policy错误?

To close the issue, the error was that Android didn't seem to know how to handle localhost . 为了解决这个问题,错误是Android似乎不知道如何处理localhost Changing the domain to http://10.0.2.2 solved the problem. 将域更改为http://10.0.2.2解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM