java - 通过 Android 模拟器和 xampp 服务器连接到本地主机

标签 java php android

通过 android 程序运行 php 脚本,并提供本地主机地址,例如

try {
        url = "http://10.0.2.2:80/xxx/";
        //optionally I tried
        //url="http://localhost/xxx/";
        //url="http://192.168.1.8/xxx/";
        //url="http://127.0.0.1/xxx/";
        //above all options are not working for me. 
        httpclient = new DefaultHttpClient();
        request = new HttpGet(url);
        response = httpclient.execute(request);
    }
try {
        BufferedReader rd = new BufferedReader(new InputStreamReader(
                response.getEntity().getContent()));
        String line = "";
        while ((line = rd.readLine()) != null) {

            // Appending result to textview
            result.append(line);
        }

即使我检查了防火墙设置,上述所有网址也无法连接,但它不起作用。 需要帮助,我被困在这个线程中。

最佳答案

要从 Android 模拟器访问本地主机,请使用 ipconfig 中给出的 IP 地址。

打开命令提示符 -> 输入 ipconfig -> 获取 IPV4 地址...例如 192.xx...

enter image description here

所以你的URL =“http://192.xx.xx.xx/folder/file.php”

使用您的 Android 浏览器测试此网址...如果可以连接,那么 Android 应用程序中应该没有问题

关于java - 通过 Android 模拟器和 xampp 服务器连接到本地主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26713026/

相关文章:

java - 将两个 Jtable 添加到 JScrollPane

php - $con->用PHP查询MySQL错误

php - 从多个表中选择MySQL记录并排序

android - NPE @ android.support.v7.widget.RecyclerView$LayoutManager.detachViewInternal

Android BackupManager和与同一帐户关联的多个设备

java - 从 Eclipse 启动 Tomcat 的访问冲突

java - 从 PHP 调用 Java 程序

java - 如何将 JerseyJaxrsConfig 类添加到 grizzly 作为 servlet

php - PEAR - 为什么要通过 CLI 安装?

android - 从 TravisCI 将 Android aar 库上传到 bintray