【问题标题】:How to get static ip address?如何获取静态IP地址?
【发布时间】:2012-09-26 01:45:34
【问题描述】:

我正在为我的一门大学课程构建一个 android 应用程序。我有一个使用 xampp 在我的笔记本电脑上运行的 localhost 服务器。我手机上运行的 android 应用程序必须连接到 localhost 才能从 MySQL 数据库中获取数据(通过 php 脚本)。我在代码中使用 HTTPClient 连接到服务器。该代码工作正常,但由于我的 IP 地址发生变化,我需要不断更改 HTTPpost 中的 url。我的问题是如何获得静态 IP 地址?我需要它在任何地方工作,例如我将在家里编码和测试,但我最终必须在大学展示一个有效的应用程序。 这是我的 HTTP 代码:

private String[] url = new String[] { "http://172.24.25.204:80/comp5615/select.php" };
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url[0]);
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(param));
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            //read content
            is =  httpEntity.getContent();  
            result = convertStreamToString(is);
        } catch (Exception e) {
            Log.e("log_tag", "Error in http connection "+e.toString());
        }

【问题讨论】:

    标签: android xampp localhost static-ip-address


    【解决方案1】:

    您的问题与android无关,它更多地与如何获取静态IP地址有关,以便您的本地PC可以充当服务器,您可以随时随地连接。

    在我在我的电脑上托管几个测试网站的日子里,我遇到了同样的问题。而且我正在使用 no-ip.com 服务来进行全时连接。还有 dyn.com 和 opendns.com

    基本上你要做的是安装他们的软件并在你的系统中保持活跃,而不是连接到他们的服务器,他们会给你 ip 或子域名,你用它来连接你的动态 ip。并且他们的软件一直在与您的 ip 通信,即使在 ip 更改时也能保持您的服务器在线。

    【讨论】:

    • 我按照你的建议做了,并从 no-ip.com 获得了一个 ip..但是我现在如何连接到 localhost?当我使用分配的 IP 地址时,它不起作用。
    • 您需要下载并安装他们的软件并使其保持活动状态。软件会将您的动态 IP 与他们给您的静态 IP 连接起来。
    【解决方案2】:
    you can get Static IP Address in browser as well as programmability in application. 
    this is url return the static IP adress 
    

    "http://api.exip.org/?call=ip"

    in android normally we request above mention url and getting response  of it
    

    【讨论】:

      猜你喜欢
      • 2022-11-27
      • 2016-01-26
      • 2020-04-26
      • 2018-11-04
      • 2016-08-27
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多