Axios
2
3
在請求中使用代理
const axios = require('axios');
// 您的目標網址,此處以 http://ipinfo.io/ 為例
const targetUrl = 'http://ipinfo.io/';
const proxyConfig = {
host: '您的代理主機',
port: 您的代理連接埠,
protocol: 'http',
auth: {
username: '您的使用者名稱',
password: '您的密碼'
}
};
async function fetchData() {
try {
// 將 proxyConfig 作為選項傳遞給 axios.get
const response = await axios.get(targetUrl, { proxy: proxyConfig });
console.log('Success:', response.data);
} catch (error) {
console.error('Fail:', error.message);
}
}
fetchData();最后更新于