Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29603

How to allow Self-Signed Certificates on Android with React Native

$
0
0

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


Viewing all articles
Browse latest Browse all 29603

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>