B. Rain
B. Rain

Reputation: 135

net::ERR_CONNECTION_REFUSED on cordova app

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="[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>

Upvotes: 4

Views: 11889

Answers (3)

pxeba
pxeba

Reputation: 1776

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

Upvotes: 0

spodell
spodell

Reputation: 166

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.

Upvotes: 2

Gandhi
Gandhi

Reputation: 11935

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.

Upvotes: 4

Related Questions