简体   繁体   English

Phonegap应用程序与php服务器通信而不使用IP地址

[英]Phonegap app communicate with php server without using ip address

Question: How can I get a phonegap application (using ajax) to communicate with a php server inside a local network without knowing the server's IP address? 问题:如何在不知道服务器IP地址的情况下如何使phonegap应用程序(使用ajax)与本地网络中的php服务器通信?

I tried using the hostname as the URL ( http://hostname/ ) and it works on my computer's browser but it doesn't work on android or in my application. 我尝试使用主机名作为URL( http:// hostname / ),它可以在我的计算机的浏览器上运行,但是在android或我的应用程序中不起作用。

Right now, the server has a static IP address but I would like for the application to work with a server that has a dynamic IP address instead. 现在,服务器具有一个静态IP地址,但是我希望该应用程序可以与具有动态IP地址的服务器一起使用。

I came across a couple of questions on here that were similar except they required connecting to an external server ( http://jsonip.appspot.com/ ) and they returned the IP address given by the service provider. 我在这里遇到了两个类似的问题,除了它们需要连接到外部服务器( http://jsonip.appspot.com/ ),并返回了服务提供商提供的IP地址。 I am looking for something to run in a local network to give the IP address assigned by the router. 我正在寻找可以在本地网络中运行的设备,以提供路由器分配的IP地址。

The only other thing I could think of was sending a UDP broadcast which, from what I've read, is hard to do if not impossible. 我唯一想到的另一件事就是发送UDP广播,根据我的阅读,即使不是不可能,也很难做到这一点。

Would anyone be able to provide some more input or options? 谁能提供更多输入或选择?

Thanks 谢谢

EDIT: 编辑:

$.ajax({
    type: "POST",
    dataType: "JSON",
    url: "http://home-server/application.php",
    data: {username: $("#username").val(), password: $("password").val()}
    success: function(data) {
        if (data == "approved") {
            //redirect user to home page
        } else if (data == "invalid") {
            //clear form
        }
    },
    error: function(x, exception) {
        alert("Error");
    }
});

The url works on my computer but android/phonegap can't resolve the url. 该网址可以在我的计算机上使用,但android / phonegap无法解析该网址。 I read up on the access element and my understanding of it led me to try the following without luck: 我阅读了access元素,对它的理解使我尝试了以下运气:

<access origin="http://home-server/" />
<access origin="http://home-server/application.php" />
<access origin="*" />

You don't need to define the IP address, you can use the domain without problems. 您无需定义IP地址,可以毫无问题地使用域。 Is posible you have not access to connect to with the server. 可能您无权连接到服务器。

Try add on your config.xml: 尝试在您的config.xml上添加:

<access origin="http://yourdomain.com" />

Or: 要么:

<access origin="*" />

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

相关问题 使用 IP 地址与 android 设备通信 - Using IP address to Communicate with android device 使用phonegap,Android设备是否可以与PHP通信? - Using phonegap, is there a way for an Android device to communicate with PHP? 通过 phonegap 应用程序从同一网络中的移动设备与本地服务器通信 - Communicate with local server from a mobile in the same network through a phonegap app 使用PHP的IP地址不可靠 - IP Address using PHP not reliable 获取没有服务器端语言的IP地址 - Getting an IP address without a server side language 我可以在不使用外部服务的情况下通过chrome应用程序获取IP地址吗? - Can I get my IP address in a chrome app without using an external service? 使用 ExpressJS 应用程序查找客户的 IP 地址 - Find the clients' IP address using an ExpressJS app 使用 javascript 和 php (NO jQuery) 与 mysql 服务器 (MariaDB) 安全通信 - Securely communicate with mysql server (MariaDB) using javascript and php (NO jQuery) 不用ajax,jquery或其他库即可使用javascript获取IP地址 - get ip address with javascript without using ajax, jquery or another library 如何使用javascript或jQuery获取不带IP或主机名的URL地址? - How to get a URL address without IP or hostname using javascript or jQuery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM