Loading

关于android返问网络时访问本地服务器无效,访问外网有效,但是浏览器可以访问本地服务器的解决办法

出现这个原因是因为搭建服务器时大多数时候没有特别设置为https的模式
而新版安卓(Q以及以上)会默认不允许访问http
所以我们要在添加配置来修改
1.先创建一个配置的xml文件

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

然后在AndroidManifest.xml中的application标签中配置该文件

 android:networkSecurityConfig="@xml/network_security_config"

如图所示
在这里插入图片描述
然后重新编译运行即可

posted @ 2021-03-26 22:43  克豪  阅读(146)  评论(0)    收藏  举报