节点https请求实际上是http
有人可以告诉我,为什么这个https请求在nodejs中:
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? 在debugging-http日志中看起来像这样:
'→GET http://www.something.com/api/v1/method?from=2017-01-01&to=2017-01-25 '
它正在工作,我确实得到的结果,但我宁愿使用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" } };
至:
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" } };
- 强制连接在nodejs中的一段时间后closures
- EADDRNOTAVAIL经过许多http.get请求到localhost
- cURL的formsaxios或ajax是什么?
- 如何在express js中添加'res.addHeader(“Access-Control-Allow-Origin”,“*”)?
- 如何从Google Cloud Functions发送HTTP请求(nodeJS)
- 在NodeJs中,我怎么才能等到我的http获得完成?
- node.js – 请求 – 如何“emitter.setMaxListeners()”?
- 如何检索HTTP响应错误的详细信息
- Node.js xml2jsparsing器未定义