Christian Berg Christian Berg - 7 months ago 38
Node.js Question

How can I use an http proxy with node.js http.Client?

I want to make an outgoing HTTP call from node.js, using the standard

. But I cannot reach the remote server directly from my network and need to go through a proxy.

How do I tell node.js to use the proxy?


Tim Macfarlane's answer was close with regards to using a HTTP proxy.

Using a HTTP proxy (for non secure requests) is very simple. You connect to the proxy and make the request normally except that the path part includes the full url and the host header is set to the host you want to connect to.
Tim was very close with his answer but he missed setting the host header properly.

var http = require("http");

var options = {
  host: "proxy",
  port: 8080,
  path: "",
  headers: {
    Host: ""
http.get(options, function(res) {

For the record his answer does work with but that's because their server doesn't care the host header is incorrect.