[英]NodeJS Request Post not working for HTTPS website
我正在使用NodeJS 請求 - 簡化的HTTP客戶端
我似乎在使用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));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.