react-native 在Android 9.0 上请求fetch http失败

骑猪看日落 2023-07-19 12:15 45阅读 0赞

android 9.0 默认禁止访问不安全的请求,比如http,采坑……

解决方法:

+方法一: 使用认证过的https(我用的阿里云免费证书,如果使用https还得配置,所以用了http)
+方法二(两步):

第一步: 在 res 下新增一个 xml 目录,然后创建一个名为:network_security_config.xml 文件

如下图:

format_png

image.png

内容如下:

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

第二部:

AndroidManifest.xml文件中添加

  1. android:networkSecurityConfig="@xml/network_security_config"

如下图:

format_png 1

链接:https://www.jianshu.com/p/9f2853e05697

发表评论

表情:
评论列表 (有 0 条评论,45人围观)

还没有评论,来说两句吧...

相关阅读

    相关 fetch请求详解

    最新更新时间:2019年06月04日16:18:30 [`《猛戳-查看我的博客地图-总有你意想不到的惊喜》`][-_-] > 本文内容:fetch相关 概述