gpt4 book ai didi

ssl - Protractor node-libcurl 失败 : SSL peer certificate or SSH remote key was not OK

转载 作者:行者123 更新时间:2023-12-04 22:39:26 27 4
gpt4 key购买 nike

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

Failed: SSL peer certificate or SSH remote key was not OK

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 : *'
],
})

如何摆脱这个错误。

最佳答案

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

You need to set either CAINFO or CAPATH options, or disable SSLverification with SSL_VERIFYPEER (not recommended).

The certificate file can be obtained in multiple ways:

  • Extracted directly from your system/browser

  • Downloaded from https://curl.haxx.se/docs/caextract.html, which is based on the onefrom Firefox

  • Creating a file with the contents of tls.rootCertificates, which was added with Node.js v12.3.0, example:

    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 }))

关于ssl - Protractor node-libcurl 失败 : SSL peer certificate or SSH remote key was not OK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63052127/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com