问题
I'm trying to make an API call to a https:// resource using Axios inside React Native.
I'm making the call as follows:
const instance = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
});
instance.get('https://foodspecials-api.local/api/v1/specials/2')
.then((response) => {
console.log('WORKED');
console.log(response);
})
.catch((e) => {
console.log('FAILED');
console.log(e);
});
This, however, results in an error message ReferenceError: Can't find variable: https
I've created a SSL certificate which is self-signed.
Is there a workaround for this?
回答1:
you should import 'https' module import https from 'https', to do this install this react-native module node-libs-react-native.
来源:https://stackoverflow.com/questions/51098851/react-native-allow-self-signed-certificates-using-axios