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

empty response from requestb.in #213

Closed
pahud opened this issue Jul 18, 2016 · 4 comments
Closed

empty response from requestb.in #213

pahud opened this issue Jul 18, 2016 · 4 comments

Comments

@pahud
Copy link

pahud commented Jul 18, 2016

Hello,

I am having problem getting response from requestb.in with got.stream, did I miss anything?

pahud-mb12:~ pahud$ cat c.js
'use strict';

const got = require('got')
const url = 'http://requestb.in/1234gpr1'

got.stream( url )
 .on('response', resp=>console.log( resp.read() ))
$ node c.js
null
$ curl http://requestb.in/1234gpr1
ok
@floatdrop
Copy link
Contributor

@pahud [it is recommended](node js readable stream to string) to listen on data event to get data:

'use strict';

const got = require('got')
const url = 'http://requestb.in/1234gpr1'

got.stream( url )
 .on('response', resp=>resp.on('data', chunk => console.log(chunk) ))

// or
// got.stream( url ).on('data', chunk => console.log(chunk));

@hustcer
Copy link

hustcer commented Aug 31, 2016

@floatdrop
It seemed that the end event of res never triggered?
Or did I missed something? Thanks.

resp.on('end', function(){
    console.log('This never happened?');
});

@floatdrop
Copy link
Contributor

@hustcer it could be related to #223 – try to listen on returned stream from got:

got.stream( url ).on('end', () => console.log('Ended'));

@hustcer
Copy link

hustcer commented Aug 31, 2016

@floatdrop
I have tried:

got.stream( url ).on('end', () => console.log('Ended'));

but still not work.
I want to get the full response body, something like this:

            let body = '';
            res.on('data', data => {
                body += data.toString();
            })
            .on('end', () => {
                console.log(body);
            });

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

3 participants