java.net.ConnectException:10000 毫秒后无法连接到/192.168.1.107(端口 80):isConnected 失败:EHOSTUNREACH(没有到主机的路由) [英] java.net.ConnectException: failed to connect to /192.168.1.107 (port 80) after 10000ms: isConnected failed: EHOSTUNREACH (No route to host)

查看:80
本文介绍了java.net.ConnectException:10000 毫秒后无法连接到/192.168.1.107(端口 80):isConnected 失败:EHOSTUNREACH(没有到主机的路由)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的 REST API 从本地主机与 android 应用程序连接起来.我在 Windows 上使用 xampp 作为我的 apache 服务器.当我尝试通过 Postman 使用此链接从我的计算机获取时,其余 api 可以正常工作:

I'm trying to connect my REST API from localhost with android application. I'm using xampp as my apache serever on my Windows. The rest api works correctly when I'm trying to get from my computer using this link via Postman:

http://127.0.0.1/RightBoard/Web/right-board/public/api/login

在 Android 设备上,我尝试使用 Volley 获取响应.这是我的代码:

On android device I'm trying to fetch response with Volley. and this is my code:

fun post(url: String, params: MutableMap<String, String>, listener: ResponseListener, token: String = "") {
    val request = object : StringRequest(
            Request.Method.POST,
            url,
            Response.Listener<String> {
                listener.onResponseReceived(JSONObject(it))
            },
            Response.ErrorListener {
                it.printStackTrace()
                if (it.networkResponse?.data != null) {
                    val json = JSONObject(it.networkResponse.data.toString(Charsets.UTF_8))
                    Log.e(Keys.TAG, json.toString())
                }
            }
    ) {
        override fun getParams(): MutableMap<String, String> {
            return params
        }

        override fun getHeaders(): MutableMap<String, String> {
            val headers = HashMap<String, String>()
            headers["Authorization"] = "Bearer $token"
            return headers
        }
    }
    request.retryPolicy = DefaultRetryPolicy(
            10000,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
    )
    VolleySingleton.instance?.addToRequestQueue(request)
}

url 是 http://192.168.1.107/RightBoard/Web/right-board/public/api/login 我得到 IP="192.168.1.107" 来自 ipconfig.但现在我收到此错误:

url is http://192.168.1.107/RightBoard/Web/right-board/public/api/login and I get the IP="192.168.1.107" from ipconfig. but now I'm getting this error:

java.net.ConnectException: failed to connect to /192.168.1.107 (port 80) after 10000ms: isConnected failed: EHOSTUNREACH (No route to host)

我已经检查过手机和电脑是否在同一个 wifi 中.我在另一部手机上运行该应用程序.我什至尝试重新启动计算机和 xampp ......但每次都出现相同的错误.我也在我的应用程序中使用了权限:

I've checked that both phone and computer are in the same wifi. I run the app in another phone. I even tried restarting computer and xampp... but same error every time. I've also used the permission in my app :

<uses-permission android:name="android.permission.INTERNET"/>

推荐答案

我找到了解决方案.我禁用了 Windows Defender 防火墙(仅在我的网络处于活动状态的私人部分)

I found the solution. I disabled the Windows Defender Firewall ( In just private section where my network was active)

这篇关于java.net.ConnectException:10000 毫秒后无法连接到/192.168.1.107(端口 80):isConnected 失败:EHOSTUNREACH(没有到主机的路由)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆