将http请求的结果存储到变量

时间:2014-09-01 12:30:38

标签: node.js

嗨我收到网页内容的问题。请参阅下面的代码

var http = require('http');
var html = '';
var options = {
    host: 'dev.gunship.io',
    path: '/node.html'
};
callback = function(response) {
    response.on('data', function(chunk) {
        html += chunk;
    });
    response.on('end', function() {
        //console.log(html);
    });
};
http.request(options, callback).end();
console.log(html);

为什么我的控制台没有记录任何内容..? 感谢您的帮助

0 个答案:

没有答案
相关问题