React Native allow self signed certificates using axios

随声附和 提交于 2019-12-13 04:17:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!