net :: ERR_CONNECTION_REFUSED在cordova应用上 [英] net::ERR_CONNECTION_REFUSED on cordova app

查看:143
本文介绍了net :: ERR_CONNECTION_REFUSED在cordova应用上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所述,当我按登录按钮使用Ajax调用发送GET请求时,我在单独的android设备上从chrome的远程调试中收到此错误.但是,它可以在浏览器上正常工作.我已经更改了js文件网址中的IP地址,使其指向我的公共IP.

As the title states, I am getting this error from chrome's remote debugging on a separate android device, when I press the login button to send a GET request using ajax call. It works fine on a browser, however. I've changed the IP address in the URLs on my js files to point to my public IP.

我已检查并遵循建议的步骤,例如将Content-Security-Policy标头添加到index.html,还检查了cordova插件白名单,将allow-intent和allow-navigation添加到我的config.xml文件中,以及还向我的index.html文件的标题添加了cordova.js脚本,但是错误仍然存​​在.

I've checked around and followed recommended steps like adding the Content-Security-Policy header to the index.html and also checking for the cordova plugin whitelist, adding allow-intent and allow-navigation into my config.xml file and also adding the cordova.js script to the header of my index.html file, however the error persists.

我对此并不陌生,因此我不确定是否还有其他因素可能导致此错误,例如必须启用域.这是错误的屏幕截图.请告诉我是否还有更多信息可以提供.

I'm new to this therefore I am unsure if there are any more factors that could cause this error, such as the domain having to be live. Here is the screenshot of the error. Please do tell me if there is any more information I can provide.

以下是代码:

index.html

<!DOCTYPE html>
<html>
  <head>
    <title>AGW</title>
    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval' http://PublicIPAddress/MP/applogin.php">
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
    <!-- include css file here-->
    <!-- include JavaScript file here-->
    <script src="cordova.js"></script>
    <script type= "text/javascript" src="js/jquery-3.1.1.js"></script>
    <script type="text/javascript" src="js/validlogin.js"></script>

  </head>   
  <body>
    <div class="container">
        <div class="main">
          <form class="form"  method="post" action="#">
            <h2>AGW</h2><hr/>

            <label>Email :</label>
            <input type="text" name="email" id="email"> <br />
            <br />
            <label>Password :</label>
            <input type="password" name="password" id="password"> <br />
            </form><br />
            <br />          
            <input type="submit" name="login" id="login" value="Login">
          </form>   
        </div>
   </div>

  </body>
</html>

config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>AWG Rewards System</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <allow-intent href="http://127.0.0.1/MP/*" />
    <allow-intent href="http://PublicIPAddress//MP/*" />
    <allow-navigation href="*" />
    <allow-intent href="*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

推荐答案

问题在于config.xml中指定的允许意图配置

The issue is with the allow-intent configuration specified in config.xml

config.xml同时指定了通配符和基于IP的允许意图配置.更正此配置并提及正确的IP应该可以完成这项工作.

The config.xml has both wildcard and IP based allow-intent configurations specified. Correcting this configuration and mentioning proper IPs should make this work.

这篇关于net :: ERR_CONNECTION_REFUSED在cordova应用上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆