Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch in react native wont work with ssl on android

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'.

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?

like image 286
Jesper Lugner Avatar asked Nov 11 '15 17:11

Jesper Lugner


People also ask

Is react native compatible with Android?

Overview. React Native is an open-source mobile application framework created by Facebook. It is used to develop applications for Android, iOS, Web and UWP (Windows) providing native UI controls and full access to the native platform. Working with React Native requires an understanding of JavaScript fundamentals.


1 Answers

There is a few workarounds for this issue mentioned here: Trust Anchor not found for Android SSL Connection

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.

Then I configure nginx (my server behind nginx) with: ssl_certificate /etc/nginx/ssl/fullchain.pem;

The original document: https://www.digicert.com/ssl-certificate-installation-nginx.htm

Hope that helps

like image 110
idealweek.net Avatar answered Sep 21 '22 10:09

idealweek.net