I need to make an API request using this cURL
curl -L -i -X PUT –cert ./[device_cert].pem –key ./[device_cert_private_key].pem -H 'Content-Type: application/json' -H 'Content-Encoding: utf-8' -d '{"registrationId": "[registration_id]"}' https://global.azure-devices-provisioning.net/[ID_Scope]/registrations/[registration_id]/register?api-version=2021-06-01
And I convert it to axios, it seems like this
const data = { registrationId: registrationId, }; const cert = await RNFS.readFile(certificatePath, 'utf8'); const key = await RNFS.readFile(keyPath, 'utf8'); console.log('cert', cert); console.log('key', key); try { const httpsAgent = new https.Agent({ cert: cert, key: key, }); console.log('httpsAgent', httpsAgent); const response = await axios({ method: 'PUT', url: `https://global.azure-devices-provisioning.net/${scopeId}/registrations/${registrationId}/register?api-version=2021-06-01`, data: data, httpsAgent: httpsAgent, headers: {'Content-Type': 'application/json','Content-Encoding': 'utf-8', }, }); return response.data; } catch (err) { console.log('err', err); return err; }
In node we have API called https
which provide Agent
method to add certificate and private for API request as
const httpsAgent = new https.Agent({cert:cert,key:key})
But react native doesn't support https
.
So I tried multiple packages such rn-nodeifynode-libs-react-nativereact-native-ssl-pinningI can't use nodejs-mobile-react-native as app size increases a lot with this package.How can I use https.Agent
in react native?Thank You