Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] http get empty response #37

Open
Cologler opened this issue Oct 21, 2018 · 0 comments
Open

[BUG] http get empty response #37

Cologler opened this issue Oct 21, 2018 · 0 comments

Comments

@Cologler
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant