跨源资源共享(CORS)问题

时间:2014-09-10 07:46:55

标签: curl cross-domain cors cdn

我在Rackspace CDN中存储字体(font-awsome)并在我的网站中使用它。字体无法加载,错误信息为:

    Font from origin 'http://some address.rackcdn.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.my domain.com' is therefore not allowed access. 

我知道这是CORD的问题,因此我使用rackspace API为容器和文件Access-Control-Allow-Origin: *设置Access-Control-Allow-Origin。 通过curl命令进行验证:

   curl -I -X HEAD http://some addresss.rackcdn.com/production/assets/fontawesome-webfont-5019d8b3ed6173ce677c8fb2cfaf70c4.ttf

结果:

    HTTP/1.1 200 OK
    Last-Modified: Wed, 10 Sep 2014 07:20:04 GMT
    ETag: c4668ed2440df82d3fd2f8be9d31d07d
    X-Timestamp: 1410333603.37481
    Access-Control-Allow-Origin: *
    Content-Type: application/x-font-truetype
    X-Trans-Id: txbcf7f6de9f7848359081c-00540ffbd4dfw1
    Cache-Control: public, max-age=259176
    Expires: Sat, 13 Sep 2014 07:20:28 GMT
    Date: Wed, 10 Sep 2014 07:20:52 GMT
    Connection: keep-alive

我也可以通过在浏览器中输入地址栏的URL来下载字体。但是我仍然无法在我的网站中使用该字体,之前的错误消息仍然存在。

我也试过用javascript测试:

    request = new XMLHttpRequest()
    request.open('GET', 'http://my file url);
    request.send(null)

错误消息是

   XMLHttpRequest cannot load http://my file url. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://www.google.com' is therefore not allowed access. 

Access-Control-Allow-Origin: *似乎不足以解决CORS问题。我应该在Rackspace CDN上使用Rackspace CDN中的字体添加更多内容以便使用Rackspace CDN中的字体?

谢谢!

0 个答案:

没有答案