Android 中 failed to connect to /127.0.0.1 (port 18080) from /127.0.0.1 (port 59190) 解决办法

Android 中 isConnected failed: ECONNREFUSED解决办法

问题产生

今天运行一个师兄的项目,前端是Android,后端是springboot。搞了老半天,Android和springboot项目都跑起来了,在具体Android访问后端的时候报错了

错误如下:

W/System.err: Caused by: java.net.ConnectException: failed to connect to /127.0.0.1 (port 18080) from /127.0.0.1 (port 59190) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)

我看了url也没有错误,把师兄的url也改成了自己的localhost,为什么会报错呢?

解决过程

不会就上百度,百度输入关键字找了好一会儿,然后终于找到了。原来是因为模拟器默认把127.0.0.1和localhost当做本身了,所以我把后端请求的url也设置为127.0.0.1或者localhost,那就等于自己访问自己,所以出错了。

解决办法

把访问后端的url改成自己的本机的ip,然后重新启动Android程序,问题解决!

猜你喜欢

转载自blog.csdn.net/weixin_43520670/article/details/115034232
今日推荐