【问题标题】:React Native allow self signed certificates using axiosReact Native 允许使用 axios 进行自签名证书
【发布时间】:2018-06-29 09:43:02
【问题描述】:

我正在尝试在 React Native 中使用 Axios 对 https:// 资源进行 API 调用。

我按如下方式拨打电话:

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);
            });

但是,这会导致错误消息 ReferenceError: Can't find variable: https

我创建了一个自签名的 SSL 证书。

有解决办法吗?

【问题讨论】:

  • 错误与new https.Agent 行有关,请检查您的导入
  • @Vivek 我知道这一点。从哪里导入 https?
  • 你有答案吗?
  • 有解决办法吗?

标签: javascript ssl react-native https axios


【解决方案1】:

https 模块适用于 nodejs(不适用于 react-native)

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2019-03-01
  • 2018-11-26
  • 1970-01-01
  • 2020-05-22
  • 2015-05-08
  • 2017-06-19
  • 2017-12-19
  • 2017-02-19
  • 2021-06-11
相关资源
最近更新 更多