【问题标题】:net::ERR_CONNECTION_REFUSED on cordova app科尔多瓦应用程序上的 net::ERR_CONNECTION_REFUSED
【发布时间】:2017-06-20 08:30:56
【问题描述】:

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

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

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

代码如下:

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>

【问题讨论】:

  • 您在 config.xml 中的 allow-intent 配置既有通配符也有 IP 规范 (allow-intent href="PublicIPAddress//MP*") 。您能否只使用通配符并检查?
  • 啊!我知道了。我按照您的步骤,还将代码中的IP地址更改为本地IP而不是公共IP,这样它就可以工作了。
  • 很高兴它成功了。为他人的利益发布答案。如果有帮助,请采纳并投票。干杯

标签: javascript android cordova


【解决方案1】:

问题在于 config.xml 中指定的 allow-intent 配置

config.xml 指定了通配符和基于 IP 的允许意图配置。更正此配置并提及正确的 IP 应该可以完成这项工作。

【讨论】:

【解决方案2】:

对我来说,它是在我的 index.html 中将以下内容添加到我的“Content-Security-Policy”中,这似乎是随着更高版本的cordova-android(我使用的是 9.1.0和 10.1.1)

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多