微信扫一扫看面试题

关注面试题库

node.js 中使用 request发起请求时报 Error: unable to verify the first certificate

解决办法

安装 request-promise

const request = require('request-promise');
var options = {
    method: 'POST',
    uri: 'http://api.posttestserver.com/post',
    "rejectUnauthorized": false, 
    body: {
        some: 'payload'
    },
    json: true // Automatically stringifies the body to JSON
};
 
rp(options)
    .then(function (parsedBody) {
        // POST succeeded...
    })
    .catch(function (err) {
        // POST failed...
    });

重点是加上     "rejectUnauthorized": false  即可

posted @ 2022-07-23 10:02  web前端面试小助手  阅读(306)  评论(0)    收藏  举报