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

查看:172
本文介绍了CORS请求在Safari中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在发出CORS xhr请求。这在chrome中工作得很好,但是当我在safari中运行时,我得到一个无法加载访问控制允许原点不允许访问。代码是完全相同的,我已经在服务器上设置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的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.

推荐答案

感谢所有的回应,我终于自己了。我将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天全站免登陆