javascript - NodeJS 请求发布不适用于 HTTPS 网站

标签 javascript node.js loopbackjs

我正在使用 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));

关于javascript - NodeJS 请求发布不适用于 HTTPS 网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46968937/

相关文章:

loopbackjs - Strongloop 环回 : How can I add related model instances on a model instance in a boot script

http - Nodejs 反向代理性能

node.js - Loopback [nodejs] 自动迁移/自动更新模型到 mongodb

javascript - 更改 "value"控件中所选选项的 "Select"属性

c# - 如何从母版页代码页获取应用程序路径?

javascript - 过滤 Angular Table td 时出现问题

php - 有什么东西不见了吗?在不刷新\重新加载页面的情况下更改\更新页面内容

node.js - 显示当前使用 node/express/socket.io 构建的聊天中的用户

node.js - POST 请求将空值插入 MS SQL 数据库

node.js - 当两个包同名时如何安装正确的 NPM 包?