react-native Android上网络请求失败,报错信息:Network request failed
在http网络请求时,react-native或者Android报错:Network request failed时原因:android9.0以上由于安全性高了,所有不做处理http不能使用,解决方法有如下三种1.降级targetSdkVersion的版本,降到27或27以下2.服务器请求http改为https (推荐)3.兼容http请求# 在清单文件中设置networkSecurityConf
·
在http网络请求时,react-native或者Android报错:Network request failed时
原因:android9.0以上由于安全性高了,所有不做处理http不能使用,解决方法有如下三种
1.降级targetSdkVersion的版本,降到27或27以下
2.服务器请求http改为https (推荐)
3.兼容http请求
# 在清单文件中设置networkSecurityConfig属性
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config">
</application>
</manifest>
# 在res/xml文件夹下创建network_security_config.xml
<?xml version ="1.0" encoding ="utf-8"?> <network-security-config> <base-config cleartextTrafficPermitted="true"> <trust-anchors> <certificates src="system" /> </trust-anchors> </base-config> </network-security-config>
更多推荐
所有评论(0)