NodeJS 请求 Post 不适用于 HTTPS 网站

NodeJS Request Post not working for HTTPS website

我正在使用 NodeJS Request - Simplified HTTP Client

我似乎在使用 HTTPS 网站时遇到问题,我没有得到结果。

var request = require('request');

request.post({
    url: "",//your url
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    },

    form: {
        myfield: "myfieldvalue"
    }
},function (response, err, body){
    console.log('Body:',JSON.parse(body));
}.bind(this));

在 Postman 上测试了 API 端点(我无法共享),我只是关闭 SSL 并且它可以工作,我如何对请求插件做同样的事情?

只需添加以下行:

    rejectUnauthorized: false,//add when working with https sites
    requestCert: false,//add when working with https sites
    agent: false,//add when working with https sites

因此您的代码将如下所示:

var request = require('request');

request.post({
    url: "",//your url
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    },
    rejectUnauthorized: false,//add when working with https sites
    requestCert: false,//add when working with https sites
    agent: false,//add when working with https sites
    form: {
        myfield: "myfieldvalue"
    }
},function (response, err, body){
    console.log('Body:',JSON.parse(body));
}.bind(this));