2020-03-23 HTTP FAILED: java.net
2020-03-23 本文已影响0人
骑着家雀吃辣条
在Android O 升 P (8.0升9.0)的时候,会报以下异常
HTTP FAILED: java.net.UnknownServiceException: CLEARTEXT communication to 192.168.1.29 not permitted
因为 Android P 是默认禁止访问http的API的 所以想要跳过https的限制要这样做
在res文件夹下创建xml目录,新建network_https_config.xml文件
内容:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
然后
在AndroidManifest.xml的Application中添加配置引用
<application
..
android:networkSecurityConfig="@xml/network_https_config"
... >
</application>
完美解决!