问题
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.
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>
回答1:
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.
来源:https://stackoverflow.com/questions/42016284/neterr-connection-refused-on-cordova-app