【问题标题】:protractor node-libcurl Failed: SSL peer certificate or SSH remote key was not OKprotractor node-libcurl 失败:SSL 对等证书或 SSH 远程密钥不正确
【发布时间】:2020-07-23 10:27:57
【问题描述】:

我正在尝试在量角器项目中使用 node-libcurl 模块,但出现错误:

失败:SSL 对等证书或 SSH 远程密钥不正确

const  {curly} = require('node-libcurl')
const { data } = await curly.post('https://www.example.com', {
  postFields: JSON.stringify({"name":"rak"}),
  httpHeader: [
    'Content-Type: application/json',
    'Accept: application/json',
    'Access-Control-Allow-Origin : *'
  ],
})

如何摆脱这个错误。

【问题讨论】:

    标签: ssl protractor node-libcurl


    【解决方案1】:

    来自COMMON_ISSUES.md file on the project's repository

    您需要设置 CAINFOCAPATH 选项,或禁用 SSL 使用SSL_VERIFYPEER 进行验证(不推荐)。

    证书文件有多种获取方式:

    • 直接从您的系统/浏览器中提取

    • https://curl.haxx.se/docs/caextract.html下载,基于 来自火狐

    • 用Node.js v12.3.0添加的tls.rootCertificates的内容创建一个文件,例如:

      const fs = require('fs')
      const path = require('path')
      const tls = require('tls')
      
      const { curly } = require('node-libcurl')
      
      // important steps
      const certFilePath = path.join(__dirname, 'cert.pem')
      const tlsData = tls.rootCertificates.join('\n')
      fs.writeFileSync(certFilePath, tlsData)
      
      async function run() {
        return curly.post('https://httpbin.org/anything', {
          postFields: JSON.stringify({ a: 'b' }),
          httpHeader: ['Content-type: application/json'],
          caInfo: certFilePath,
          verbose: true,
        })
      }
      
      run()
        .then(({ data, statusCode, headers }) =>
          console.log(
            require('util').inspect(
              {
                data: JSON.parse(data),
                statusCode,
                headers,
              },
              null,
              4,
            ),
          ),
        )
        .catch((error) => console.error(`Something went wrong`, { error }))
      

    【讨论】:

      猜你喜欢
      • 2012-12-20
      • 2022-07-19
      • 2016-10-16
      • 2014-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 2015-11-13
      相关资源
      最近更新 更多