【问题标题】:Failed to load resource: net::ERR_CONNECTION_REFUSED Cordova android无法加载资源:net::ERR_CONNECTION_REFUSED Cordova android
【发布时间】:2019-10-10 07:44:21
【问题描述】:

我正在使用cordova开发一个android应用程序,我在调用api时遇到了以下问题,请帮我解决这个问题

Failed to load resource: net::ERR_CONNECTION_REFUSED(http://ip address:8080)


var uName = $('#UserName_input').val();
    var pwd = $('#Password_input').val();
    console.log("GetLogin function CallED~~~~~~~~~~~~~");
    console.log("GetLogin InternetStatus ~~~~~~~~~~~~~" + InternetStatus);
    console.log("GetLogin function uNam~~~~~~~~~~~~~" + uName);
    console.log("GetLogin function pwd ~~~~~~~~~~~~~" + pwd);
    if (InternetStatus == 'Online') {
        if (uName != "" && pwd != "") {
            //SpinnerDialog.show("Loading", "Please Wait...", true);
            $(".modal").show();
            /*---------->*/
            // alert("call before AJAX------>");
            debugger
            $.ajax({
                    url: baseURL + checkLogin,
                    type: 'POST',



                    data: {
                        'userName': uName,
                        'password': pwd
                    },
                    // ~~~~~~~~~~~~~~~~~  Basic autherntication ~~~~~~~~~~~~~~~~~~~~~~~~
                    /* beforeSend: function(xhr) {
                         xhr.setRequestHeader("Authorization", "Basic " + btoa("crewMobieAppAdmin" + ":" + "!uT#61@c#"));
                     },*/
                    success: function(result)
                        //we got the response
                        {

                            //debugger
                            console.log("message------>" + result.message + " \n status----->" + result.status);
                            //console.log(JSON.stringify(row));
                            if (result.status == "success") {

                                UserDatails(uName, result.tokenId);
                                ToastShow("Login Successfully.!!!", "#008000", "#FFFFFF");
                                USERNAME_localStorage_SET(uName);
                                PASSWORD_localStorage_SET(pwd);
                                BASEAUTH_localStorage_SET(result.tokenId);
                                PIN_localStorage_SET("");
                                SpinnerDialog.hide();
                                window.location.href = "home.html"
                                    //$(".modal").hide();

                            } else {
                                SpinnerDialog.hide();
                                ToastShow(result.message, "#FF0000", "#FFFFFF");
                                // $(".modal").hide();

                            }
                            //SpinnerDialog.hide();
                            // $(".modal").hide();
                        },
                    error: function(exception) {
                        ToastShow("Server not responding. Please try again after some time.!!!", "#FF0000", "#FFFFFF");
                        console.log('Exception:' + exception);
                        status = "failur"
                            // Hide spinner dialog
                            //SpinnerDialog.hide();
                            // $(".modal").hide();
                    }

                }) /*<----------*/
                // SpinnerDialog.hide();

        } else {
            ToastShow("Please enter valid username and password.!!!", "#FF0000", "#FFFFFF");
        }

    } else {
        ToastShow("please check your network connection and try again.!!!", "#FF0000", "#FFFFFF");
    }

【问题讨论】:

  • 您在 config.xml 中的设置是否正确?调试控制台中的实际错误是什么?
  • 加载资源失败:net:: ERR_CONNECTION_REFUSED 这只是我从 chrome 调试@Gandhi 得到的
  • 您可以尝试使用浏览器平台建立连接以隔离问题吗?

标签: android cordova


【解决方案1】:

这可能是版本兼容性问题。查看类似问题的答案here

否则,这可能是因为您在应用程序中阻止了 API URL。在 config.xml 中设置以下值

<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

注意:这不是推荐的生产设置。如果此解决方案适合您,请考虑微调您的 URL。请参阅Whitelisting URLS - Cordova Documentation 了解有关如何配置此功能的更多详细信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-08
    • 1970-01-01
    • 2015-04-02
    • 1970-01-01
    • 2023-03-29
    • 2014-12-17
    相关资源
    最近更新 更多