我使用带有代理选项的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.`);
});
但实际上超时并没有起作用,它花了很长时间去捕获块。
发布于 2020-07-17 00:28:38
使用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()
https://stackoverflow.com/questions/62938735
复制相似问题