android - Fetch in react native 不能在 android 上使用 ssl

标签 android ssl fetch react-native

当我在我的 React native 应用程序中使用 fetch 函数时,一切在 iOS 上按预期工作,但在 android 中出现错误。错误是“类型错误:网络请求失败”。做了一些调试,我发现错误的原因似乎如下:'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found'。

为什么这适用于 iOS 而不是 Android,我该如何最好地解决它?是 react-native 的错误,还是更深层次的错误?

最佳答案

这里提到的这个问题有一些解决方法:Trust Anchor not found for Android SSL Connection

但是,如果您是服务器所有者。我建议检查您的服务器 ssl 证书。我认为那是因为您的 pem 文件中缺少 CA 证书。 我为我的网站所做的是通过按顺序连接 file.crt 和 file.ca-bundle 的内容来创建 fullchain.pem。

然后我配置 nginx(我的服务器在 nginx 后面): ssl_certificate/etc/nginx/ssl/fullchain.pem;

原始文档:https://www.digicert.com/ssl-certificate-installation-nginx.htm

希望对你有帮助

关于android - Fetch in react native 不能在 android 上使用 ssl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33655832/

相关文章:

android - 尊重当前语言环境的自定义 Android 日期格式

android - 将数据从 mysql 数据库传输到 sqlite 数据库。(Android-JSON)

ssl - key /证书管理的最佳实践

ssl - 在 gitlab ce 中使用 LetsEncrypt 和谷歌站长工具

javascript - 将 fetch 调用到 fetch 的 Promise 中是一种不好的做法吗?

android - 如何为 Firebase 身份验证用户设置自定义用户 UID?

java - TableRow 在 TableLayout 中返回空值?

java - 无法访问位于 : https://example. com?wsdl 的 WSDL。它失败并显示 : sun. security.validator.ValidatorException

javascript - 无法从 SvelteKit 中的 API 获取数据

javascript - slim /工兵 : Body empty on POST