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

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

解决方法:

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

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

如下图:

image.png

内容如下:

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

第二部:

AndroidManifest.xml文件中添加

 android:networkSecurityConfig="@xml/network_security_config"

如下图:


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

发布了270 篇原创文章 · 获赞 102 · 访问量 50万+

猜你喜欢

转载自blog.csdn.net/hahahhahahahha123456/article/details/105213192
今日推荐