我想从这样的网址数组中获取数据响应:
let arrUlr = [ 'https://my.domain.base/api/v1/people/?auth_token=71bdf0377bc%%$%&count=100&page=1',
'https://my.domain.base/api/v1/people/?auth_token=71bdf0377bc%%$%&count=100&page=2',
'https://my.domain.base/api/v1/people/?auth_token=71bdf0377bc%%$%&count=100&page=3',
'https://my.domain.base/api/v1/people/?auth_token=71bdf0377bc%%$%&count=100&page=4',
'https://my.domain.base/api/v1/people/?auth_token=71bdf0377bc%%$%&count=100&page=5',
'https://my.domain.base/api/v1/people/?auth_token=71bdf0377bc%%$%&count=100&page=6' ]
大量数据分块发送;我的策略是在arrUlr
中迭代 for loop
,但是为了防止这种情况,我需要延迟时间:
来自CloudFlare的消息(服务器似乎避免频繁服务请求):
response:
{ status: 429,
statusText: 'Too Many Requests',
headers:
{ date: 'Tue, 04 Jun 2019 22:37:00 GMT',
'transfer-encoding': 'chunked',
connection: 'close',
'set-cookie': [Array],
status: '429 Too Many Requests',
'cache-control': 'no-cache',
'x-ratelimit-limit': '3',
'x-ratelimit-reset': '2019-06-04 22:37:01 UTC',
'x-request-id': '0fa7395b-df8d-4c8a-bc5b-52d0e46c4138',
'x-runtime': '0.001619',
'x-ratelimit-period': '1',
'x-powered-by': 'Phusion Passenger Enterprise',
'expect-ct': 'max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"',
server: 'cloudflare',
'cf-ray': '4e1d63897b2db594-BOG' }, ... ]
这是我的主意:
for(let url of arrUlr){
/*for(let i=0; i < arrUlr.lenght; i++) is a alternative*/
setTimeout( ()=>{
axios.get(url)
.then(res =>{
console.log(res.data) /*whatever it comes*/
})
}, 5000)
}
非常感谢。