joepie91 / node-bhttp

A sane HTTP client library for Node.js with Streams2 support.
62 stars 12 forks source link

[BUG] http get empty response #37

Open Cologler opened 6 years ago

Cologler commented 6 years ago

example code:

const url = 'http://m.qpic.cn/psb?/V12z2enq1EDXnj/mhPPlRUa73TiD7MyHUNr3RAp17dG*cKq91Q*cvA4lrQ!/b/dFIBAAAAAAAA&bo=fgKCAwAAAAADB98!&rf=viewer_4';

function useNodeHttp() {
    const http = require('http');
    http.get(url, res => {
        if (res.statusCode !== 200) {
            console.error(`Status Code: ${res.statusCode}`);
        }

        let rawData = '';
        res.on('data', chunk => { rawData += chunk; });
        res.on('end', () => {
            console.log(`node.http got data: ${rawData.length}`);
        });
    });
}

async function useBHttp() {
    const bhttp = require("bhttp");
    const response = await bhttp.get(url);
    if (response.body.length === 0) {
        console.log(`bhttp got data: ${response.body.length}`);
    }
}

(async function() {
    useNodeHttp();
    useBHttp();
})();

output:

bhttp got data: 0
node.http got data: 1001303