O
O
Oleg Yatsenko2014-07-24 19:57:23
Node.js
Oleg Yatsenko, 2014-07-24 19:57:23

Why is not the full body of the response passed to the callback in request?

The callback is called erroneously - it receives error, response and body of the request, while body contains only part of the response, and response.complete is false.
error is null

request({
    pool:false,
    agent:false,
    url:'http://api.example.com/',
    method:'POST',
    json:true,
    form:{user_id:user_id.join(',')}
},function(error,response,body){
    ...
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Yatsenko, 2014-09-08
@Samber

The problem was on the side of the requested server - it was cutting off connections ahead of time.

M
maxism, 2014-07-25
@maxism

Request means github.com/mikeal/request?
If so, then this is probably some very specific bug due to the sufficient distribution of this module. However, I advise: make sure you use the latest version of the module (boring, but sometimes useful) and since request uses the standard nodejs module for http requests, try to pull the data in an old cool manner

var options = {
    pool:false,
    agent:false,
    url:'http://api.example.com/',
    method:'POST',
    json:true,
    form:{user_id:user_id.join(',')}
};

var req = request(options);

var data = '';

req.on('data', function (chunk) {
  data += chunk.toString('utf8');
});

req.on('end', function () {
  console.log(data);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question