Safari 10.1:由于访问控制检查,无法加载带有查询参数的 XMLHttpRequest

2022-01-15 00:00:00 cors javascript safari

Safari 10.1 上尝试 CORS 请求 时,在包含查询参数(例如 https://example.com/api?v=1),Safari 说

When trying a CORS request on Safari 10.1, on an URL which includes query parameters (e.g. https://example.com/api?v=1), Safari says

XMLHttpRequest 由于访问控制检查而无法加载

XMLHttpRequest cannot load due to access control checks

Chrome/Firefox 运行良好.

Chrome/Firefox works fine.

对于来自没有 ?v=1 的页面的请求,Safari 也可以正常工作.

On requests from the page without the ?v=1, Safari works fine too.

我尝试从

Access-Control-Allow-Origin: https://example.com

Access-Control-Allow-Origin: https://example.com/api?v=1

但这会破坏 Chrome.

but that breaks Chrome.

有什么建议吗?

推荐答案

如果有人遇到这个错误,它只是发生在我正在构建的应用程序中.就我而言,它原来是 uri 中的尾随/,导致 301 响应,出于某种原因,Safari 将其解释为 500 响应.

If anyone comes across this error, it just occurred in the application I was building. In my case, it turned out to be a trailing / in the uri, which caused a 301 response, which was for some reason interpreted by Safari as a 500 response.

相关文章