最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Why is my node.js get response being truncated - Stack Overflow

programmeradmin2浏览0评论

I am making a request to the facebook api to get a list of friends. When I make the request through node.js, my request is always truncated. Does anyone understand why the response is being truncated?

Here is the code of my function:

var loadFriends;
loadFriends = function(access_token, callback) {
  var https, options, start;
  https = require('https');
  start = new Date();
  options = {
    host: 'graph.facebook',
    port: 443,
    path: '/me/friends?access_token=' + access_token
  };
  return https.get(options, function(res) {
    console.log("Request took:", new Date() - start, "ms");
    res.setEncoding("utf8");
    return res.on("data", function(responseData) {
      var data;
      console.log(responseData);
      data = JSON.parse(responseData);
      return callback(data);
    });
  });
};

I am making a request to the facebook api to get a list of friends. When I make the request through node.js, my request is always truncated. Does anyone understand why the response is being truncated?

Here is the code of my function:

var loadFriends;
loadFriends = function(access_token, callback) {
  var https, options, start;
  https = require('https');
  start = new Date();
  options = {
    host: 'graph.facebook.',
    port: 443,
    path: '/me/friends?access_token=' + access_token
  };
  return https.get(options, function(res) {
    console.log("Request took:", new Date() - start, "ms");
    res.setEncoding("utf8");
    return res.on("data", function(responseData) {
      var data;
      console.log(responseData);
      data = JSON.parse(responseData);
      return callback(data);
    });
  });
};
Share Improve this question edited Aug 2, 2011 at 5:27 Osei Bonsu asked Aug 1, 2011 at 2:45 Osei BonsuOsei Bonsu 1071 silver badge10 bronze badges 2
  • Please tag this with the language or framework you're using, as this is not JavaScript/node.js. – Dan Grossman Commented Aug 1, 2011 at 2:49
  • I converted it from coffeescript to javascript and tagged it appropriately – Osei Bonsu Commented Aug 1, 2011 at 2:54
Add a ment  | 

1 Answer 1

Reset to default 7

The res.on('data') event will happen multiple times as chunks of data arrives; you need to concatenate this together to get the whole response.

http://nodejs/docs/v0.4.0/api/http.html#event_data_

发布评论

评论列表(0)

  1. 暂无评论