4
votes

I'm developing a React Native App makes http / https requests. I'm doing for both platforms Android and iOS. I am facing with a problem that don't let me fetch an url with self-signed certificate. I have tested that this is working with other url that aren't self-signed. There is a way to force React Native to trust in Self-Signed certificates?

The error that I get when I execute the fetch() function is this:

TypeError: Network request failed

Here I post my code:

const form = new FormData();
form.append('parameters[ticketPerson]', this.state.ticketPerson);
form.append('rawxmlresponse', 'false');

fetch(this.state.url, {
    method: 'POST', headers: { Connection: 'close' },
    body: form,
})
.then(response => response.json())
.then(async (responseJson) => {
  console.log('repsonse --->', responseJson);
})
.catch((error) => {
  console.log('ERROR ---> ', error);
});

It works on iOS, only fail on Android. And this code works on Android if the url is not a Self-signed certificate.

Avoid responses like "You shouldn't trust in" or "Just Sign it and will work".

1
The main purpose of the certificate is to be sure to talk to the correct site. You totally loose that if you accept self signed certificates. So even if you don't want to hear that: "You shouldn't trust in".Henry
Thanks you for nothingSmoggeR_js
Did you ever manage to get this resolved? Facing similar issue.Darrel K.
I had to change the certificates by server side. Also I had similar problems due to TSL2 because Android < 5 won't connect with it.SmoggeR_js

1 Answers

0
votes

I had to change the certificates by server side. Also I had similar problems due to TSL2 because Android < 5 won't connect with it