网络请求失败CLEARTEXT communication to “ “ not permitted by network security policy

ok http3 + retrofit 网络请求,在Android9.0手机上请求失败,报错:CLEARTEXT communication to " " not permitted by network security policy

  • 原因 :Android P以后网络访问安全策略升级,限制了非加密的流量请求
  • 办法:1.降低目标版本,app/build.gradle中targetSdkVersion 设置27或以下。
    2.http请求改成https。
    3.添加res/xml/network.xml文件名可自拟 网络请求失败CLEARTEXT communication to “ “ not permitted by network security policy_第1张图片
    在Androidmanifest.xml中设置networkSecurityConfig指向上述文件
    网络请求失败CLEARTEXT communication to “ “ not permitted by network security policy_第2张图片

你可能感兴趣的:(http请求,Android9.0,android,网络)