在反应原生中获取不会在 android 上与 ssl 一起使用

Fetch in react native wont work with ssl on android(在反应原生中获取不会在 android 上与 ssl 一起使用)

本文介绍了在反应原生中获取不会在 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 一起使用

基础教程推荐