0

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', function (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?

1 Answer 1

1

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);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.