How to configure axios to use SSL certificate?

前端 未结 4 1646
广开言路
广开言路 2020-12-02 12:39

I\'m trying to make a request with axios to an api endpoint and I\'m getting the following error: Error: unable to verify the first certificate

It seems

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 12:57

    Create a custom agent with SSL certificate:

    const httpsAgent = new https.Agent({
      rejectUnauthorized: false, // (NOTE: this will disable client verification)
      cert: fs.readFileSync("./usercert.pem"),
      key: fs.readFileSync("./key.pem"),
      passphrase: "YYY"
    })
    
    axios.get(url, { httpsAgent })
    
    // or
    
    const instance = axios.create({ httpsAgent })
    

    From https://github.com/axios/axios/issues/284

提交回复
热议问题