3

I have a react-native application which I'm hooking up to an existing API which already has two clients (webapp, chrome extension). For some reason I just get the generic [TypeError: Network request failed] with nothing more.

The requests that are failing are just basic get requests such as fetch('https://api.mydomain.com/pages/') or axios.get('https://api.mydomain.com/pages/') and they work fine from the webapp and chrome extension that are using this API as well - the requests only fail from the react-native application.

Everything I'm finding on google for this is in regards to localhost or SSL Certificate problems, although these are not my issues because I'm trying to pull from a deployed server and also that server has SSL correctly enabled and I'm using the https endpoint.

Some more notes:

  • when I do go against localhost (using the IP Address, not localhost address) I get this same error.
  • I'm getting this error on Android and I haven't touched nor am concerned yet with iOS
  • I get this same error with fetch and axios
  • The request goes through OK with this endpoint https://jsonplaceholder.typicode.com/posts/1 and I get back a response

This last note is the most interesting because I believe that means there is some issue with my server, however my server is not receiving any request... I have opened up CORS for testing purposes but have the same issue, although if that were the issue the server would have received the request and responded with 403.

4
  • Show a code snippet where you fetched please. Commented Jan 11, 2018 at 1:55
  • added, just the most basic stuff failing Commented Jan 11, 2018 at 2:04
  • Do the requests to your server work if you simply use them in a regular web app (non-react-native)? Commented Jan 11, 2018 at 2:42
  • yes they work fine from a react webapp and from a react chrome extension Commented Jan 11, 2018 at 14:02

1 Answer 1

1

This has to do with Android not trusting my SSL certificate. Apparently Android has some additional trust requirements on top of what web browsers require.

I found this through error.request._response via the axios catch block which showed me the error java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

After figuring that out, the root cause ended up being my SSL Certificate uploaded to AWS didn't have the correct intermediate cert which was fine in chrome, but not in android.

Sign up to request clarification or add additional context in comments.

3 Comments

can you please explain more about your solution? I have search a lot and no succeed! I have a server with self signed certificate and I have to use it (I can not change it for some reasons) also I have to use fetch library and no other similar libraries. please provide a step-by step answer. I think a lots of people have my problem based on my searches
Yes please explain the solution. This is driving me nuts. My API is in Azure and I'm having similar problems.
i use the aws-cli for uploading ssl cert to aws. I was just uploading the csr and certificate but needed to upload the csr, intermediate and certificate. Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.