Javascript Post方法使用https.request工作,但不使用针头或请求库
我没有睡意。它确实有用 在某个特定的时间,我需要与野外的API进行通信。在rest工具(如Postman)中使用API非常简单: 邮递员 通过邮递员发送上述信息,我得到了快速的回复!是的,休息工具 所以他们的API可以工作,现在我需要在Node.js应用程序中做出同样的响应 这就是事情变得奇怪的地方 请求模块:失败 上述方法失败了。。它抛出了一个我们都喜欢的好错误!为什么?谁知道呢 https.request()-有效! 但是我注意到。。。 如果我在使用请求模块时将这行代码保留在适当的位置,那么它就会工作Javascript Post方法使用https.request工作,但不使用针头或请求库,javascript,node.js,post,express,node-request,Javascript,Node.js,Post,Express,Node Request,我没有睡意。它确实有用 在某个特定的时间,我需要与野外的API进行通信。在rest工具(如Postman)中使用API非常简单: 邮递员 通过邮递员发送上述信息,我得到了快速的回复!是的,休息工具 所以他们的API可以工作,现在我需要在Node.js应用程序中做出同样的响应 这就是事情变得奇怪的地方 请求模块:失败 上述方法失败了。。它抛出了一个我们都喜欢的好错误!为什么?谁知道呢 https.request()-有效! 但是我注意到。。。 如果我在使用请求模块时将这行代码保留在适当的位置,那么
var https = require("https");
https.globalAgent.options.secureProtocol = 'SSLv3_method';
这是否有文档记录,而我却没有?有人给我解释一下吗
var request = require('request')
...lots_of_other_stuff...
var options = {
uri: 'https://epicURL',
method: 'POST',
json: true,
headers : {
"Content-Type":"application/json",
"Accept":"application/json",
"x-key":"secretbro"
},
body : JSON.stringify(bodyModel)
};
request(options, function(error, response, body) {
if (!error) {
console.log('Body is:');
console.log(body);
} else {
console.log('Error is:');
logger.info(error);
}
cb(body); //Callback sends request back...
});
var https = require("https");
https.globalAgent.options.secureProtocol = 'SSLv3_method';
var headers = {
"Content-Type":"application/json",
"Accept":"application/json",
"x-key":"nicetrybro"
}
var options = {
host: 'www.l33turls.com',
port:443,
path: "/sweetpathsofjebus",
method: 'POST',
headers: headers
};
var req = https.request(options, function(res) {
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
});
res.on('end', function() {
var resultObject = responseString;
//Call the callback function to get this response object back to the router.
cb(resultObject);
});
});
req.on('error', function(e) {
console.log(e);
});
req.write(bodyString);
req.end();
var https = require("https");
https.globalAgent.options.secureProtocol = 'SSLv3_method';