Android - 尝试连接到本地服务器时出错(Xampp)

卡里姆·阿塔

这是我的 logcat 和我尝试连接的 url 的第一行,它是有效的 url

这是我的 logcat 和我尝试连接的 url 的第一行,它是有效的 url

她是我的代码导致错误并使连接拒绝

public static String makeHttpRequest(URL url) throws IOException {
    String jsonResponse = "";
    Log.e(LOG_TAG, url.toString());

    // If the URL is null, then return early.
    if (url == null) {
        return jsonResponse;
    }

    HttpURLConnection urlConnection = null;
    InputStream inputStream = null;
    try {
        urlConnection = (HttpURLConnection) url.openConnection();

        urlConnection.setReadTimeout(10000 /* milliseconds */);
        urlConnection.setConnectTimeout(15000 /* milliseconds */);
        urlConnection.setRequestMethod("GET");
        urlConnection.connect();

        // If the request was successful (response code 200),
        // then read the input stream and parse the response.
        if (urlConnection.getResponseCode() == 200) {
            inputStream = urlConnection.getInputStream();
            jsonResponse = readFromStream(inputStream);
        } else {
            Log.e(LOG_TAG, "Error response code: " + urlConnection.getResponseCode());
        }
    } catch (IOException e) {
        Log.e(LOG_TAG, "Problem retrieving the Category JSON results.", e);
    } finally {
        if (urlConnection != null) {
            urlConnection.disconnect();
        }
        if (inputStream != null) {
            inputStream.close();
        }
    }
    return jsonResponse;
}

我已经知道如何使 Http 连接并且以前做过很多但这是第一次在本地服务器上

萨加尔

由于模拟器和笔记本电脑的本地主机不同,您需要执行以下操作:

  1. 使用ipconfig笔记本电脑命令提示符中的命令获取 PC 的 IP 地址
  2. localhost您应该ipAddress在 URL中使用而不是使用

所以你的地址会变成: http://<ip address>/lotus/getstats.php?category=ATM

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将Android客户端连接到NodeJS中的套接字服务器时出错

Android,socket.io,握手时出错,连接到Node.js服务器时

使用 volley 连接到 android 中的服务器时出现内部服务器错误?

Android手机无法连接到VMware上安装的XAMPP服务器

从Android连接到XMPP服务器

如何从Android模拟器连接到本地服务器?

从 Android 模拟器连接到本地 asp.net web 服务器

如何从Android使用asynctask连接到Neo4j服务器(本地主机)

如何将android设备连接到本地服务器?

如何在Android Studio中连接或链接到本地主机服务器地址

通过互联网从本地服务器连接到Android

Android应用程序需要帮助来连接到Java本地主机服务器

活动在后台时,Android服务无法连接到服务器

尝试从Gitea连接到AD服务器时出错

通过android模拟器连接到服务器

连接到Java服务器时Android客户端崩溃

代号一:在与Android上具有SSL证书的服务器建立连接时出错

Android浏览器无法连接到本地nanohttpd服务

Android无法连接到服务器进行注册或登录

Android Studio 连接到 Socket 服务器

Android:将httpURLConnection连接到服务器

无法在Android Smartphone上连接到FTP服务器

无法连接到Android中的Node JS服务器

[React Native] [Android]无法连接到开发服务器

Android studio - 无法连接到 LDAP 服务器

少于api 23的Android无法连接到服务器

通过WIFI将Android连接到SQL服务器

通过 Android Emulator 连接到 Java 服务器

如何将android应用程序连接到本地计算机作为服务器