访问控制 - 允许原素非常奇怪的行为
我对API的要求非常奇怪。基本上,一切都在开始时起作用,然后突然停止工作,给CORS错误。
$.ajax({
url: `https://stockx.com/api/products/${url}?includes=market¤cy=EUR`,
type: 'get',
success: function(json) {
console.log(json);
}
});
正如我所说的那样,该代码以前对我有用,但是现在发生了一些非常奇怪的事情,它开始给我这个错误:
通过'https://stockx.com/api/products/nike-air-max-max-1-travis-scott-wheat?includes=market'访问XMLHTTPREQUEST'被CORS策略阻止:“ Access-Control-Allow-Origin”标题具有一个值'https://stockx.com',不等于所提供的来源。
然后,我决定将Access-Control-Allow-Origin标头添加到我的请求中,但是此错误之后有所更改为:
通过'https://stockx.com/api/products/nike-air-max-max-1-travis-scott-wheat?includes=market'访问XMLHTTPREQUEST'被CORS策略阻止:对飞行前请求的响应不会传递访问控制检查:“访问 - 控制 - 柔和 - 孔”标头具有一个值'https://stockx.com'的值,该值不等于所提供的来源。
毕竟,由于频繁的要求,我认为我被禁止使用此API,但我仍然可以使用浏览器或Postman访问此API。
您建议我做什么?
PS我正在尝试创建WordPress插件,因此所有脚本都在WordPress下运行。
I have very strange error making request to API. Basically everything worked at the beginning and then suddenly stopped working giving CORS error.
$.ajax({
url: `https://stockx.com/api/products/${url}?includes=market¤cy=EUR`,
type: 'get',
success: function(json) {
console.log(json);
}
});
As I said this code worked for me before but now something very strange happened and it started giving me that error:
Access to XMLHttpRequest at 'https://stockx.com/api/products/nike-air-max-1-travis-scott-wheat?includes=market' from origin 'http://hbd.local' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value 'https://stockx.com' that is not equal to the supplied origin.
Then I decided to add Access-Control-Allow-Origin header to my request but after that error a bit changed to:
Access to XMLHttpRequest at 'https://stockx.com/api/products/nike-air-max-1-travis-scott-wheat?includes=market' from origin 'http://hbd.local' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://stockx.com' that is not equal to the supplied origin.
After all I thought that I got banned on this API due to frequent requests but I can still access this api using my browser or postman.
What would you recommend me to do?
P.S I'm trying to create wordpress plugin, so all script are running under wordpress.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想从另一个网站或REST API进行HTTP请求,则可以使用Serveride Rendering。就像go.rice一样,next.js,go纤维等。
if you want to http request from another website or rest api, you can use serverside rendering. just like go.rice, next.js, go fiber etc. you can google it like how to use server side rendering web application