Axios
2
3
Use the Proxy in a Request
const axios = require('axios');
// Your target URL, here we use http://ipinfo.io/
const targetUrl = 'http://ipinfo.io/';
const proxyConfig = {
host: 'your-proxy-host',
port: your-proxy-port,
protocol: 'http',
auth: {
username: 'your-username',
password: 'your-password'
}
};
async function fetchData() {
try {
// Pass proxyConfig as an option to axios.get
const response = await axios.get(targetUrl, { proxy: proxyConfig });
console.log('Success:', response.data);
} catch (error) {
console.error('Fail:', error.message);
}
}
fetchData();Last updated