Tuesday 17 November 2020

React Native Axios allow self signed ssl certificate

I'm writing an app in React Native, and I need to make API requests. The server for that is running on a server with a self-signed SSL certificate, so I need Axios and React Native to make the request and accept the response using a self-signed certificate.

  • I can't get a certificate from an official certificate authority.
  • I have already tried using https.Agent, however this doesn't seem to be possible when using React Native (The https module is part of the node standard library, which is not included in React Native), so this is also not a valid solution.
  • I would prefer to continue using Axios, however I would consider switching libraries if there are any with similar functionality (I've already tried a few, none provided functionality to allow self-signed certs).

Here is some example code from my project (url is the IP of the server):

import axios from 'axios';

const instance = axios.create({ });
instance.get(url)
    .then(res => {
        this.setState({dataSource: res.data});
     })

Btw, when I'm using ngrok everything works fine, so the self-signed certificate is definitely the only problem.



from React Native Axios allow self signed ssl certificate

No comments:

Post a Comment