在React Native中获取不会与Android上的ssl一起使用 [英] Fetch in react native wont work with ssl on android

查看:114
本文介绍了在React Native中获取不会与Android上的ssl一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在React Native应用程序中使用fetch函数时,事情在iOS上可以正常运行,但在android中却出现错误.错误为"TypeError:网络请求失败".进行一些调试后,我发现错误的原因似乎是以下原因:"java.security.cert.CertPathValidatorException:找不到证书路径的信任锚".

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上起作用,我如何最好地解决它?是本机故障还是更深层的故障?

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?

推荐答案

此处提到了一些针对此问题的解决方法:

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

希望有帮助

这篇关于在React Native中获取不会与Android上的ssl一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆