![](/img/trans.png)
[英]CORS header 'Access-Control-Allow-Origin' missing but it present in the header
[英]CORS “No 'Access-Control-Allow-Origin' header is present” yet there is
这三个标头是使用PHP添加的
header('Content-Type: application/json; charset=UTF-8;');
header('Access-Control-Allow-Methods: GET, POST');
header('Access-Control-Allow-Origin: *');
发送的所有标头都是:
HTTP/1.1 200 OK
Date: Mon, 30 Jun 2014 06:39:29 GMT
Server: Apache
X-Powered-By: PHP/5.3.28
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Access-Control-Allow-Methods: GET, POST
Access-Control-Allow-Origin: *
Vary: Accept-Encoding,User-Agent
Content-Encoding: gzip
Cache-Control: max-age=1, private, must-revalidate
Content-Length: 20
Keep-Alive: timeout=3, max=100
Connection: Keep-Alive
Content-Type: application/json; charset=UTF-8;
然而,当尝试使用$ .json或$ .post来定位此服务器时,我在Chrome控制台中收到此错误:
XMLHttpRequest cannot load http://cms.webdevguru.co.uk/gurucms.php?mode=addto&apikey=606717496665bcba. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://remote.webdevguru.co.uk' is therefore not allowed access.
我知道这可能是其他几个问题的重复,但是因为我经历过很多其他问题,并尝试了一些其中的东西来尝试解决这个问题:我会很感激一些特定的回复来处理我手头的问题。
正如Joachim Isaksson所知,因为初始标头包含301重定向,有没有办法在检查Access-Control-Allow-Origin标头之前强制请求遵循重定向?
CORS无法正常工作的原因是您的链接提供了“301 Moved Permanently”而没有CORS标头,重定向到另一个链接。
它重定向的链接发送标题,但似乎CORS已经放弃了第一个响应的预检。
使用301传回“Access-Control-Allow-Origin”标题可以解决您的问题,这应该允许预检继续。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.