更新
接受的答案对去年有好处,但今天我会使用其他人使用的包:https: //github.com/mikeal/request
原版的
我正试图抓住谷歌的徽标并使用node.js将其保存到我的服务器
这就是我现在所做的并且不起作用:
var options = {
host: 'google.com',
port: 80,
path: '/images/logos/ps_logo2.png'
};
var request = http.get(options);
request.on('response', function (res) {
res.on('data', function (chunk) {
fs.writeFile(dir+'image.png', chunk, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
});
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能使这个工作?