node.js下载带有免费公共代理的文件

时间:2014-08-01 14:59:07

标签: node.js proxy download

我想使用Node.js编写一个应用程序。应用程序的目的是通过提供URL参数来下载URL中指定的文件。例如,我想在URL http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/intl/CNNi_Logo_new.png中下载.png文件。我可以写那段代码。但我不希望对方看到我的IP(xxx.xxx.xxx.xxx)。我想在下载此文件时使用公共代理。我的意思是,当我下载此文件时,我的IP必须显示为209.170.151.142:7808(例如http://free-proxy-list.net/中的一个IP地址),但不是我的IP。

我如何在node.js中编写代码?

...问候

1 个答案:

答案 0 :(得分:0)

request模块可以采用代理配置选项:https://github.com/mikeal/request

像这样(未经测试):

var request = require('request');
request({ 
  url: 'http://domain.com/path/to/image.png',
  proxy: 'http://IP.of.proxy'
}, function (err, res, imgBuffer) {
  // check for presence of err here
  // do something with imgBuffer, like save it to a file
})