CORS "No 'Access-Control-Allow-Origin'页眉存在"


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不起作用的原因是您的链接给出了一个没有CORS头的"301永久移动",重定向到另一个链接。

它重定向到发送标题的链接,但是CORS似乎已经放弃了第一个响应的预飞行。

用301返回"Access-Control-Allow-Origin"报头可能会解决你的问题,这应该允许预飞行继续。