【问题标题】:https undefined in react native axioshttps 在本机 axios 中未定义
【发布时间】:2018-12-11 06:53:21
【问题描述】:

我已经将 axios 用于 react native 应用程序,但是在实现 https.agent 时它显示 https 是未定义的。如何解决这个问题?
我的代码

const instance = axios.create({
  httpsAgent: new https.Agent({
    rejectUnauthorized: false
  })
});

 instance.get('https://example.com');

// At request level
const agent = new https.Agent({
  rejectUnauthorized: false
});
    axios.post('/practz/login', {
          "username" :"orgadmin1@example.com",
          "password":"exam",
          "appId":"AABBCD",
          "domainName":"example.com",
          httpsAgent: agent
      })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });

【问题讨论】:

  • 你导入了 'https', const https = require('https'); 吗?
  • 是的,没有找到 https
  • 好的,你安装了吗。 $ npm install https?
  • 是的,我已经安装了
  • 这行不通,因为您不在节点环境中。 Axios 文档是这样说的:httpAgenthttpsAgent 分别定义了在 node.js 中执行 http 和 https 请求时要使用的自定义代理。这允许添加默认情况下未启用的选项,例如 keepAlive。有一个issue,您可以在其中找到资源来获取您对 https 的请求。或here

标签: reactjs react-native https axios


【解决方案1】:

这是 Android 9 或 10 的问题,您必须在 Apache 配置中添加 SSLCertificateChainFile。

SSLCertificateChainFile "/opt/bitnami/apache2/conf/server-ca.crt"

然后就可以正常使用了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-27
    • 2020-10-24
    • 2019-12-18
    • 1970-01-01
    • 2019-02-06
    • 2018-11-20
    • 2021-07-31
    • 2019-03-30
    相关资源
    最近更新 更多