【发布时间】:2018-04-02 00:15:36
【问题描述】:
我正在尝试在 Chrome 新标签扩展中使用 W3C 的 CSS Validator Web Service API。 The docs 声称请求是对 URI 的简单 HTTP GET 调用,所以我认为这应该可行:
fetch('http://jigsaw.w3.org/css-validator/validator?uri=http%3A%2F%2Fwww.w3.org%2F&profile=css3&output=json')
.then((response) => {
// do stuff with response
});
不幸的是,承诺失败,我收到如下消息:
加载失败。上没有“Access-Control-Allow-Origin”标头 请求的资源。因此不允许 Origin 访问。
如果资源不允许CORS,我应该如何发出“简单”GET 请求?
谢谢!
【问题讨论】:
-
不通过客户端JavaScript?
-
我得到这个错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://blah-blah.com' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.如果我设置{mode: 'no-cors'}它工作正常。
标签: css cors w3c w3c-validation fetch-api