node.jsproxyhttpclientproxy-authentication

proxy authentication in node.js with module request


I'm trying to use the module request in my node.js app, and I need to configure proxy settings with authentication.

My settings are something like this:

proxy:{
    host:"proxy.foo.com",
    port:8080,
    user:"proxyuser",
    password:"123"
}

How can i set my proxy configuration when i make a request? Could someone give me an example? thanks


Solution

  • Here is an example of how to configure (https://github.com/mikeal/request/issues/894):

    //...some stuff to get my proxy config (credentials, host and port)
    var proxyUrl = "http://" + user + ":" + password + "@" + host + ":" + port;
    
    var proxiedRequest = request.defaults({'proxy': proxyUrl});
    
    proxiedRequest.get("http://foo.bar", function (err, resp, body) {
      ...
    })