3

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 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.

enter image description here

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.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>
B. Rain
  • 125
  • 2
  • 8
  • 1
    Your allow-intent configuration in config.xml has both wildcards as well as IP specifications (allow-intent href="http://PublicIPAddress//MP/*") . Could you please use only wildcards and check? – Gandhi Feb 03 '17 at 04: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 Feb 03 '17 at 05:10
  • Glad it worked. Posted the answer for the benefit of others. Please accept and upvote if it was helpful. Cheers – Gandhi Feb 03 '17 at 05:26

3 Answers3

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.

Gandhi
  • 11,875
  • 4
  • 39
  • 63
  • 1
    https://stackoverflow.com/questions/58317857/failed-to-load-resource-neterr-connection-refused-cordova-android , kindly give a solution to this question – MurugananthamS Oct 11 '19 at 04:27
1

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.

spodell
  • 157
  • 12
0

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

Mithsew
  • 1,129
  • 8
  • 20