Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.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 如何使用cookie或301获取请求进行请求?_Node.js - Fatal编程技术网

Node.js 如何使用cookie或301获取请求进行请求?

Node.js 如何使用cookie或301获取请求进行请求?,node.js,Node.js,我试图获得谷歌硬盘的直接链接。第1步获取cookie,第2步获取cookie。它应该像底部一样返回直接链接。当res超过1字节时,Http请求直接结束。因为我只想获得位置直接链接。但控制台挂断了 doc-14-0c-docs.googleusercontent.com/docs/securesc/l0l6t5ueeik13q2d1k4mpkrnv5aa9ud/1sjp57s0k1pvb6cil24qhgs2kmji1pml/1619627025000/103288865324190761677/

我试图获得谷歌硬盘的直接链接。第1步获取cookie,第2步获取cookie。它应该像底部一样返回直接链接。当res超过1字节时,Http请求直接结束。因为我只想获得位置直接链接。但控制台挂断了

doc-14-0c-docs.googleusercontent.com/docs/securesc/l0l6t5ueeik13q2d1k4mpkrnv5aa9ud/1sjp57s0k1pvb6cil24qhgs2kmji1pml/1619627025000/103288865324190761677/12583675090547378677Z/0bx0piwglnix2wm1xxxzz6sdy1a2c?e=download&nonce=8fo7n5srlmjig&user=12583675054737378677qmqmhash=IIgr67505473737vql164jcl2n4fb

const https = require('https');

const url = 'https://drive.google.com/uc?export=download&confirm=5l9X&id=0Bx0piWglNIx2Wm1XXzZ6SDY1a2c';

const req = https.get(url, res => {
    const cookie = res.headers['set-cookie'][0];

    const options = {
        hostname: 'drive.google.com',
        path: '/uc?export=download&confirm=5l9X&id=0Bx0piWglNIx2Wm1XXzZ6SDY1a2c',
        port: 443,
        method: 'GET',
        headers: {
            'Cookie': cookie,
            'Referer': url
        }
    };

    console.log(res.headers);

    const reqs = https.request(options, res => {
        // res direct location
        console.log(res.headers.location);

        req.on('data', d => {
            // req end up directly when byte res above 1 byte
            if (d.length > 1) { 
                reqs.end();
            }
        });
    });
   
});

req.end();