繁体   English   中英

科尔多瓦应用程序上的 net::ERR_CONNECTION_REFUSED

[英]net::ERR_CONNECTION_REFUSED on cordova app

正如标题所述,当我按下登录按钮以使用 ajax 调用发送 GET 请求时,我在单独的 android 设备上从 chrome 的远程调试中收到此错误。 但是,它在浏览器上运行良好。 我已将 js 文件上 URL 中的 IP 地址更改为指向我的公共 IP。

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

我是新手,因此我不确定是否还有其他因素可能导致此错误,例如域必须处于活动状态。 这是错误的屏幕截图。 如果我能提供更多信息,请告诉我。

在此处输入图片说明

以下是代码:

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

配置文件

<?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中指定的allow-intent配置

config.xml同时指定了基于通配符和IP的allow-intent配置。 更正此配置并提及正确的IP应该可以使其工作。

对我来说,它在我的 index.html 中将以下内容添加到我的“内容安全策略”中,这似乎是在更高版本的cordova-android 中出现的(我使用的是 9.1.0 和 10.1。 1)

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

一旦我从我的 index.html 加载了这个 jQuery,其他库就会从 Cordova 中的 React 加载。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM