CORS request not working in Safari(CORS 请求在 Safari 中不起作用)
问题描述
我正在提出 CORS xhr 请求.这在 chrome 中运行良好,但是当我在 safari 中运行时,我得到一个无法加载 ---- Access-control-allow-origin 不允许访问".代码完全一样,我已经在服务器上设置了 CORS.下面是我的代码.(有访问控制,但你可以在没有 accessToken 的情况下自由尝试)
I am making a CORS xhr request. This works fine in chrome, however when I run in safari I get an 'Can not load ---- access not allowed by Access-control-allow-origin'. The code is exactly the same and I have set the CORS on the server. Below is my code.(has access control, but you are free to try without the accessToken)
var water;
var req = new XMLHttpRequest;
req.overrideMimeType("application/json");
req.open('GET', 'https://storage.googleapis.com/fflog/135172watersupplies_json', true);
req.setRequestHeader('Authorization', 'Bearer ' + accessToken);
origThis = this;
var target = this;
req.onload = function() {
water = req;
req.send(null);
查看请求标头后,我看到首先发出了一个 OPTIONS 请求,这是不允许的请求.原始标头不包含在 Safari 的响应中,但在 chrome 中.这是什么原因造成的.任何帮助将不胜感激.
After looking at the request headers I see that a OPTIONS request is made first and this is the request that is not allowed. The origin header is not included in the response in Safari, but is in chrome. What would cause this. Any help would be greatly appreciated.
更新:我已经在 Safari for Windows 中尝试过并且它可以工作,所以我不确定这里发生了什么.我使用的 mac 是远程访问 (Macincloud.com),但我认为这与它没有任何关系.
UPDATE: I have tried in Safari for Windows and it works, so I'm not sure what is going on here. The mac that I am using is a remote access (Macincloud.com), but I don't think that would have anything to do with it.
推荐答案
感谢大家的回复,我自己终于搞定了.我在我的 responseHeaders 中添加了Origin",现在可以正常工作了.
Thanks for all the responses, I got this finally myself. I added 'Origin' to my responseHeaders and works fine now.
这篇关于CORS 请求在 Safari 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CORS 请求在 Safari 中不起作用
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- 400或500级别的HTTP响应 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Fetch API 如何获取响应体? 2022-01-01