How to include a certificate and key in API requests in React Native?

60 Views Asked by At

I'm currently working on a React Native project where I need to make an API request that requires including a certificate and key. In a typical Node.js environment, I would use the https.Agent for this purpose. However, React Native doesn't have native support for the https module.

I've tried a few approaches, but none seem to work in the React Native environment. Here are the methods I've attempted:

Custom Axios Agent: I attempted to create a custom Axios agent using the https.Agent class, but React Native does not provide the https module.


    // This won't work in React Native
    const customAgent = new https.Agent({
    cert: cert,
    key: key,
    rejectUnauthorized: false,
    });

Native Modules: I also explored using native modules, but couldn't find a direct equivalent to the https.Agent in React Native.

    import { NativeModules } from 'react-native';
    const { RCTNetworking } = NativeModules;
    custom agent creation with RCTNetworking

How to overcome this limitation in React Native and successfully include the required certificate and key in my API requests?

0

There are 0 best solutions below