开发者

Difficulties with node.js proxy

I am attempting to make a GET request for a single image on another server from node.js.

var http = require('http');
var site = http.createClient(80, '192.168.111.190');


var proxy_request = site.request('/image.png');
proxy_request.on('response', functio开发者_运维百科n (proxy_response) {
  console.log('receiving response');
  proxy_response.on('data', function (chunk) {

  });
  proxy_response.on('end', function () {
    console.log('done');
  });
});

And even with this code, I can't get the "receiving response" message to print out. Outside of node, I can do a curl http://192.168.111.190/image.png just fine, but is there something else I might be missing?


for get requests try the http.get API http://nodejs.org/docs/v0.4.9/api/http.html#http.get

var http = require('http');

var options = {
  host: '192.168.111.190',
  port: 80,
  path: '/image.png'
};

http.get(options, function(res) {
  console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜