Skip to content

Instantly share code, notes, and snippets.

@abd1rahmane
Last active June 17, 2021 21:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abd1rahmane/e3a95c228b950c80fb5eaba202134e55 to your computer and use it in GitHub Desktop.
Save abd1rahmane/e3a95c228b950c80fb5eaba202134e55 to your computer and use it in GitHub Desktop.
Axios with Proxy
const axios = require("axios");
const { HttpProxyAgent, HttpsProxyAgent } = require("hpagent");
let useProxy = true
if (useProxy) {
var proxy = "http://USERNAME:PASSWORD@PROXYIP:PROXYPORT";
const httpsAgent = new HttpsProxyAgent({
keepAlive: true,
keepAliveMsecs: 2000,
maxSockets: 256,
maxFreeSockets: 256,
proxy: proxy,
});
const httpAgent = new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 2000,
maxSockets: 256,
maxFreeSockets: 256,
proxy: proxy,
});
axios.defaults.httpAgent = httpAgent
axios.defaults.httpsAgent = httpsAgent
}
async function getIP() {
const config = {
method: "GET",
url: "https://api.ipify.org?format=json",
};
try {
let res = await axios.request(config);
console.log(res.data);
} catch (error) {
console.log(error.message);
}
}
getIP();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment