node-curl(node.js)中的数据块

我使用node-curl作为HTTPS客户端向Web上的资源发出请求,代码在面向Internet的代理服务器后面的机器上运行。

我正在使用的代码co:

var curl = require('node-curl'); //Call the curl function. Make a curl call to the url in the first argument. //Make a mental note that the callback to be invoked when the call is complete //the 2nd argument. Then go ahead. curl('https://encrypted.google.com/', {}, function(err) { //I have no idea about the difference between console.info and console.log. console.info(this.body); }); //This will get printed immediately. console.log('Got here'); 

node-curl从环境中检测代理设置并返回预期的结果。

面临的挑战是:在整个https响应被下载后,callback被触发,并且据我所知,http(s)模块中的“数据”和“结束”事件没有相似之处。

另外,在通过源代码之后,我发现node-curl库实际上是以https://github.com/jiangmiao/node-curl/blob/master/lib/CurlBuilder中的参考行58的forms接收数据的。 js 。 在这种情况下,目前似乎没有发生任何事件。

我需要将可能的响应转发回局域网中的另一台计算机进行处理,所以这是我的一个明确的问题。

在节点中是否使用为此推荐的节点curl?

如果是,我该如何处理?

如果不是,那么将会是一个合适的替代scheme?

我会去寻求精彩的请求模块,至less如果代理设置不比它支持的更先进。 只需从环境中自行读取代理设置:

 var request = require('request'), proxy = request.defaults({proxy: process.env.HTTP_PROXY}); proxy.get('https://encrypted.google.com/').pipe(somewhere); 

或者如果你不想pipe

 var req = proxy.get({uri: 'https://encrypted.google.com/', encoding: 'utf8'}); req.on('data', console.log); req.on('end', function() { console.log('end') }); 

上面,我也通过了我期望的响应中的encoding 。 你也可以在默认值中指定(对上面的request.defaults()的调用),或者你可以保留它,在这种情况下,你将在data事件处理程序中获得Buffer s。

如果你只想把它发送到另一个URL,请求是完美的:

 proxy.get('https://encrypted.google.com/').pipe(request.put(SOME_URL)); 

或者,如果你想发布它:

 proxy.get('https://encrypted.google.com/').pipe(request.post(SOME_URL)); 

或者,如果您还想将请求代理到目标服务器,请执行以下操作:

 proxy.get('https://encrypted.google.com/').pipe(proxy.post(SOME_URL));