问题描述
我正在提出 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 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)