Fetch in react native wont work with ssl on android(在反应原生中获取不会在 android 上与 ssl 一起使用)
问题描述
当我在我的 react 本机应用程序中使用 fetch 功能时,在 iOS 上一切正常,但在 android 上出现错误.错误是TypeError:网络请求失败".做了一点调试,我发现错误的原因似乎如下:'java.security.cert.CertPathValidatorException: Trust anchor for certificate path not found'.
When I'm using the fetch function in my react native apps, things work as expected on iOS, but gives an error in android. The error is 'TypeError: Network request failed'. Doing a bit of debugging, I found that the cause of the error seems to be the following: 'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found'.
为什么这在 iOS 而不是在 android 上有效,我该如何最好地解决它?是 react-native 的问题,还是更深层次的问题?
How come this works in iOS and not on android, and how do I best fix it? Is the fault in react-native, or somewhere deeper?
推荐答案
这里提到的这个问题有一些解决方法:未找到 Android SSL 连接的信任锚
There is a few workarounds for this issue mentioned here: Trust Anchor not found for Android SSL Connection
但是,如果您是服务器所有者.我建议查看您的服务器 ssl 证书.我认为这是因为您的 pem 文件中缺少 CA 证书.我为我的网站所做的是通过将 file.crt 和 file.ca-bundle 的内容按顺序连接来创建 fullchain.pem.
However, if you are the server owner. I would suggest to review your server ssl certificate. I think that was because of missing CA certificate in your pem file. What I have done for my site is I created fullchain.pem by concating content of file.crt and file.ca-bundle as that order.
然后我配置 nginx(我在 nginx 后面的服务器):ssl_certificate/etc/nginx/ssl/fullchain.pem;
Then I configure nginx (my server behind nginx) with: ssl_certificate /etc/nginx/ssl/fullchain.pem;
原始文档:https://www.digicert.com/ssl-certificate-installation-nginx.htm
希望有帮助
这篇关于在反应原生中获取不会在 android 上与 ssl 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在反应原生中获取不会在 android 上与 ssl 一起使用


基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01