我有一个实时的restful,返回用nodeJS创建并上传到webServer的JSON数据。此外,我还使用react本机为android和IOS构建前端。api运行良好,当我在android中使用‘react原生运行-android’构建应用程序的调试版本时,返回预期的数据。但是这个应用程序似乎无法从API中获取数据,而我使用'cd && /gradlew assembleRelease‘在android中构建发布版本。在我的应用程序中,我看不到节点服务器上的任何点击。对于我的http请求,我使用axios。
发布于 2019-05-21 10:42:01
我的问题解决了。在Google的正式文档中,只有在具有有效SSL强制来自不安全域的certificate.To请求的安全域或具有自签名证书的域上,才有可能对web服务器进行请求,只需在
"yourProject/android/app/src/main/res/xml/network_security_config.xml“
有以下内容-
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<!-- For React Native Hot-reloading system -->
<!-- If you are running on a device insert your computer IP -->
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">your own domain ip</domain>
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</domain-config>
<base-config cleartextTrafficPermitted="false" />
</network-security-config>然后通过在应用程序标记-将这一行添加到AndroidManifest.xml中,导入xml文件
<application...
android:networkSecurityConfig="@xml/network_security_config"
...>发布于 2021-03-26 01:52:21
在android/app/src/main/AndroidManifest.xml中添加android:usesCleartextTraffic="true"对我来说很好。为了开发目的,我们可能还需要在调试文件夹(主的兄弟)中添加。
https://stackoverflow.com/questions/56202174
复制相似问题