【问题标题】:Disable SSL verification in Angular在 Angular 中禁用 SSL 验证
【发布时间】:2020-07-12 02:08:35
【问题描述】:

我正在尝试在 axios 中禁用角度 SSL 验证。我试过使用

axios.get(url, {
  httpsAgent: new https.Agent({  
    rejectUnauthorized: false
  })
})

但它显示错误Cannot find name 'https'.ts(2304)。所以我导入了https,然后它抛出了一个新错误Module not found: Error: Can't resolve 'https'

有没有办法在 axios 中禁用 SSL 验证?

【问题讨论】:

    标签: angular typescript axios


    【解决方案1】:

    您可以配置 axios 以使用自定义代理:

    实例

    const instance = axios.create({
      httpsAgent: new https.Agent({  
        rejectUnauthorized: false
      })
    });
    instance.get('https://something.com/foo');
    

    请求

    const request= new https.Agent({  
      rejectUnauthorized: false
    });
    axios.get('https://something.com/foo', { httpsAgent: request});
    

    希望这会有所帮助!

    【讨论】:

    • 就像我在问题中提到的,不知何故在使用https 模块时出现错误
    猜你喜欢
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 2014-02-14
    • 2011-05-03
    • 1970-01-01
    • 2018-03-18
    • 2023-02-03
    • 1970-01-01
    相关资源
    最近更新 更多