NodeJS Request Post不适用于HTTPS网站 [英] NodeJS Request Post not working for HTTPS website
本文介绍了NodeJS Request Post不适用于HTTPS网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用NodeJS 请求 - 简化的HTTP客户端
Im using NodeJS Request - Simplified HTTP Client
我似乎在使用HTTPS网站时遇到问题,我没有得到结果。
I seem to have problem working with HTTPS website, I am not getting result.
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并且它可以工作,如何对请求插件执行相同的操作?
Tested the API endpoint(which I cant share) on Postman, I just turn off SSL and it works, how do I do the same with request plugin?
推荐答案
只需添加以下行:
rejectUnauthorized: false,//add when working with https sites
requestCert: false,//add when working with https sites
agent: false,//add when working with https sites
所以你的代码看起来像这样:
So your code would look like this:
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));
这篇关于NodeJS Request Post不适用于HTTPS网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文