axiosで「unable to verify the first certificate」エラーを無視する

axiosで「unable to verify the first certificate」エラーを無視する

curlコマンドで「unable to verify the first certificate」エラーが出た場合は-kオプションで無視できますが、axiosで無視する場合は、httpsAgentオプションを指定します。

import axios from 'axios'
import https from 'https' // 追加
const options = {
  method: 'POST',
  headers: { 'content-type': 'application/x-www-form-urlencoded' },
  data: qs.stringify(jsondata),
  url: 'https://~~~',
  httpsAgent: new https.Agent({ rejectUnauthorized: false }) // 追加
}
const results= await axios(options).catch(error => {
  // error logic
})

これでhttpsで始まるURLで出てくる「unable to verify the first certificate」エラーを無視することができます。

参考サイト

How to ignore SSL issues · Issue #535 · axios/axios
Is it possible to configure Axios (running in node.js) to ignore specific SSL errors (like expired certificates)? I'd like to know that the SSL certificate has ...

curlコマンドで「unable to verify the first certificate」エラーを無視する 

コメント

タイトルとURLをコピーしました