Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用 HTTP 接口有时会提示我跨域错误('Access-Control-Allow-Origin' 响应头丢失)是怎么回事? #18

Open
cssmagic opened this issue Jun 18, 2018 · 0 comments
Labels

Comments

@cssmagic
Copy link
Member

有时,在浏览器控制台可以看到以下错误信息:

Failed to load https://mainnet.nebulas.io/v1/user/call: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'xxxx' is therefore not allowed access. The response had HTTP status code 522.

出现这种错误并不是你的代码出了问题,而是服务器不稳定,报 522 错误。522 状态码误表示 “Connection Timed Out”,连接超时。

此时往往重新请求一次就能得到正常的结果。如有必要,可以考虑在自己的代码中增加重试机制。

至于浏览器为什么会报跨域错误,大家可以详细了解一下 CORS 的原理。

@cssmagic cssmagic added the FAQ label Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant