Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 节点https请求实际上是http_Node.js_Https_Httprequest - Fatal编程技术网

Node.js 节点https请求实际上是http

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": {

有人能告诉我,为什么在nodejs中出现这种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 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"
        }
    };