Difference between revisions of "Using your Proxy Account with Node.js"

From FoxyProxy Documentation
Jump to: navigation, search
Line 4: Line 4:
 
  <nowiki>var request = require('request');
 
  <nowiki>var request = require('request');
 
request({'url':'https://icanhazip.com',
 
request({'url':'https://icanhazip.com',
         'proxy':'http://formshunt:verifybred@mutefish.getfoxyproxy.org:3128'},
+
         'proxy':'http://username:password@hostname.getfoxyproxy.org:3128'},
 
         function (error, response, body) {
 
         function (error, response, body) {
 
             if (!error && response.statusCode == 200) console.log(body);
 
             if (!error && response.statusCode == 200) console.log(body);
 
             else console.log(error);
 
             else console.log(error);
  
         });
+
         });</nowiki>
</nowiki>
+
If successful, the output is the body of http://icanhazip.com (the IP address of the proxy server). If not successful, the error message is displayed.
  
 
[http://blog.modulus.io/node.js-tutorial-how-to-use-request-module More info] about the <code style="background:gray;color:white">request</code> module in Node.js, including how to install it.
 
[http://blog.modulus.io/node.js-tutorial-how-to-use-request-module More info] about the <code style="background:gray;color:white">request</code> module in Node.js, including how to install it.
 
If successful, the output is the body of http://icanhazip.com (the IP address of the proxy server). If not successful, the error message is displayed.
 

Revision as of 03:59, 2 December 2015

This Node.js example connects to https://icanhazip.com through a proxy server with your proxy username and password. Be sure to replace username, password, hostname.getfoxyproxy.org and port (3128) in this example with your account information. In this example, the Node.js client connects to the proxy server using HTTP and instructs the proxy server to connect to the final destination (icanhazip.com) using HTTPS.


var request = require('request');
request({'url':'https://icanhazip.com',
        'proxy':'http://username:password@hostname.getfoxyproxy.org:3128'},
        function (error, response, body) {
            if (!error && response.statusCode == 200) console.log(body);
            else console.log(error);

        });

If successful, the output is the body of http://icanhazip.com (the IP address of the proxy server). If not successful, the error message is displayed.

More info about the request module in Node.js, including how to install it.