admin管理员组

文章数量:1291595

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.

I've checked around and followed remended 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.

Here are the codes:

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="" xmlns:cdv=".0">
    <name>AWG Rewards System</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="[email protected]" href="">
        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>

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.

I've checked around and followed remended 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.

Here are the codes:

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/ns/widgets" xmlns:cdv="http://cordova.apache/ns/1.0">
    <name>AWG Rewards System</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="[email protected]" 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>
Share asked Feb 3, 2017 at 3:29 B. RainB. Rain 1351 gold badge2 silver badges8 bronze badges 3
  • 1 Your allow-intent configuration in config.xml has both wildcards as well as IP specifications (allow-intent href="PublicIPAddress//MP*") . Could you please use only wildcards and check? – Gandhi Commented Feb 3, 2017 at 4:49
  • Ahh! I see. I followed your steps and also changed the IP address in the codes to the local IP instead of public IP, which allowed it to work. – B. Rain Commented Feb 3, 2017 at 5:10
  • Glad it worked. Posted the answer for the benefit of others. Please accept and upvote if it was helpful. Cheers – Gandhi Commented Feb 3, 2017 at 5:26
Add a ment  | 

3 Answers 3

Reset to default 4

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

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

For me, it was adding the following to my "Content-Security-Policy" in my index.html, the need for this seems to have arrived with a later version of cordova-android (I'm using 9.1.0 and 10.1.1)

      script-src-elem * 'self' gap: 'unsafe-inline';

Once I did this jQuery loaded from my index.html, and other libraries were loading from React within Cordova.

In my case none of the solutions worked. however I found that at least it worked without error on my remote endpoints

本文标签: javascriptnetERRCONNECTIONREFUSED on cordova appStack Overflow