CORS 请求在 Safari 中不起作用 [英] CORS request not working in Safari

查看:19
本文介绍了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 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆