当我在我的 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/