分享

java.io.IOException: Cleartext HTTP traffic to xxx.xxx.xxx.xxx not permitted

 勤奋不止 2021-02-21

Android9.0 默认是禁止所有的http

请求的,需要在代码中设置如下代码才可以正常进行网络请求: android:usesCleartextTraffic="true"。如图

  1. <application
  2. android:name="xxxx.xxxx.xxx.xxx"
  3. android:allowBackup="true"
  4. android:icon="@drawable/ic_launcher"
  5. android:label="@string/app_name"
  6. android:theme="@style/AppBaseTheme"
  7. android:usesCleartextTraffic="true">

 更高得编译版本中 使用如上配置也不起作用,需要添加配置文(network_security_config.xml)件如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <network-security-config>
  3. <base-config cleartextTrafficPermitted="true"/>
  4. </network-security-config>

之后在application中添加配置如下,即可:

  1. <application
  2. .....
  3. android:networkSecurityConfig="@xml/network_security_config"
  4. .......>

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多