Skip to content

Instantly share code, notes, and snippets.

@SanariSan
Created October 18, 2021 17:43
Show Gist options
  • Save SanariSan/c58123ca003ed87965d3928a191f85c6 to your computer and use it in GitHub Desktop.
Save SanariSan/c58123ca003ed87965d3928a191f85c6 to your computer and use it in GitHub Desktop.
Axios proxy http/s socks
// socks
// const axios_ = require("axios");
// const SocksProxyAgent = require("socks-proxy-agent");
import { default as axios_ } from "axios";
import SocksProxyAgent from "socks-proxy-agent";
const httpsAgent = new SocksProxyAgent("socks://127.0.0.1:1080");
const httpAgent = httpsAgent;
const axios = axios_.create({ httpsAgent, httpAgent });
axios({ method: "GET", url: "https://json.myip.wtf" }).then(console.log).catch(console.log);
// -------
// http/s
// const axios = require("axios");
import axios from "axios";
axios({ method: "GET", url: "https://json.myip.wtf", proxy: {
protocol: "https",
host: "127.0.0.1",
port: 1090,
auth: { username: "name", password: "pass" },
},
})
.then(console.log)
.catch(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment