var http = require('http');
var opt = {
host: 'www.baidu.com',
port: '80',
method: 'GET',
path: '/',
hearders: {
'Content-Type': 'application/json'
}
};
var body = '';
var req = http.request(opt, function (res) {
console.log('Got response: ' + res.statusCode);
res.on('data', function (data) {
body += data;
});
res.on('end', function () {
console.log(res.headers);
console.log(body);
});
});
req.on('error', function (err) {
console.log('Got error: ' + err.message);
});
req.write('');
req.end();
网友评论