java.net.UnknownServiceException: CLEARTEXT communication to 59.110.162.30 not permitted by network

在使用OkHttp进行网络请求的时候报错:java.net.UnknownServiceException: CLEARTEXT communication to 59.110.162.30 not permitted by network

原因: Android P版本(9.0)后禁止未加密的明文传输,也就是说只支持Https请求,而不支持Http请求。

解决方法: 修改网络安全策略

  1. 在res目录下创建xml文件夹,再创建network_config.xml文件
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
   <base-config cleartextTrafficPermitted="true" />
</network-security-config>
  1. 在AndroidManifest文件的application中配置android:requestLegacyExternalStorage="true"
  <application
     ...
     android:requestLegacyExternalStorage="true"
     ...
    >
   </application>
发布了51 篇原创文章 · 获赞 5 · 访问量 2608

猜你喜欢

转载自blog.csdn.net/qq_45453266/article/details/105180085
今日推荐