[英]How can i set timeout to axios that uses proxy option?
我正在使用带有代理选项的 Axios 我想检查错误的代理,所以我决定为我的 GET 请求设置超时。
这是代码:
let res= await axios.get(`http://somedomain.com`,
{
timeout:1500,
proxy: {
host: proxyList[indexOfProxy].host,
port: proxyList[indexOfProxy].port,
auth: {
username: '',
password: ''
},
}
}
).catch(err => {
console.log(`proxy ${indexOfProxy} not working.`);
});
但实际上超时没有用,它花了很长时间才到 go 来捕获块。
使用 axios.create()
const axios = require('axios').default;
const instance = axios.create({
baseURL: 'https://wainot.trade',
timeout: 5000,
});
async function run() {
try {
let res = await instance.get()
} catch (error) {
console.log('no')
}
}
run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.