Node.js 节点https请求实际上是http
有人能告诉我,为什么在nodejs中出现这种https请求:Node.js 节点https请求实际上是http,node.js,https,httprequest,Node.js,Https,Httprequest,有人能告诉我,为什么在nodejs中出现这种https请求: var options = { "method": "GET", "hostname": "www.something.com", "port": 443, "path": "/api/v1/method?from=" + dates.startDate + "&to=" + dates.endDate, "headers": {
var options = {
"method": "GET",
"hostname": "www.something.com",
"port": 443,
"path": "/api/v1/method?from=" + dates.startDate + "&to=" + dates.endDate,
"headers": {
"accept": "application/json",
"authorization": 'Basic ' + new Buffer(access.key + ':' + access.secret).toString('base64'),
"cache-control": "no-cache"
}
};
var req = https.request(options, function(res) {
var chunks = [];
res.on("data", function(chunk) {
chunks.push(chunk);
});
res.on("end", function() {
var body = Buffer.concat(chunks);
console.log(body);
});
res.on('error', function(e) {
console.log(e);
});
})
req.end();
最终以http而不是https的形式出现?在调试中,http登录如下所示:
"→ 得到
这是工作,我确实得到了结果,但我宁愿它使用https
我做错了什么?尝试更改以下内容:
var options = {
"method": "GET",
"hostname": "www.something.com",
"port": 443,
"path": "/api/v1/method?from=" + dates.startDate + "&to=" + dates.endDate,
"headers": {
"accept": "application/json",
"authorization": 'Basic ' + new Buffer(access.key + ':' + access.secret).toString('base64'),
"cache-control": "no-cache"
}
};
致:
代码是“http”;如果你想要
'https'
,那么就把它设置为。Jep,就是这样!非常感谢!:)
var options = {
"method": "GET",
"hostname": "www.something.com",
"port": 443,
"protocol": "https:",
"path": "/api/v1/method?from=" + dates.startDate + "&to=" + dates.endDate,
"headers": {
"accept": "application/json",
"authorization": 'Basic ' + new Buffer(access.key + ':' + access.secret).toString('base64'),
"cache-control": "no-cache"
}
};