因此,我一直在开发一个浏览器内程序,它使用fetch从api获取一些数据,因为api只返回数据块中的数据,所以我需要发送总共70-100个请求,一个接一个地以大约5/秒的速度发送。然而,大约50%的时间我得到一个CORS错误:
Access to fetch at 'https://api.hypixel.net/skyblock/auctions?page=49&key=7a5825e3-2d47-4ff4-894f-7fd2a6c9ca17' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.奇怪的是,当它真的发生时,错误似乎是在大约80个请求中随机出现的。我理解CORS代理的概念,但我不知道如何在实践中使用它。谁能解释一下如何使用任何CORS代理网站来避免这个错误。
发布于 2021-04-25 16:30:49
你有没有把这个添加到你的package.json:
"proxy": {
"*":{ "target" : "http://myurl"}
} 并设置标头,如:
axios.defaults.headers.post['Content-Type'] ='application/json;charset=utf-8';
axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*';https://stackoverflow.com/questions/67250935
复制相似问题