Skip to content

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

Description

@cssmagic

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

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 的原理。

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions