我试图在Chrome新选项卡扩展中使用W3C的CSS验证器Web服务API。 The docs声称的请求一个简单的HTTP GET调用的URI,所以我想这应该工作:如何在资源不允许CORS的情况下创建“简单”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
});
不幸的是,承诺失败,我得到一个消息,如:
Failed to load. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin is therefore not allowed access.
如何我应该做一个“简单的”GET
请求,如果资源不允许CORS
?
谢谢!
_不通过客户端JavaScript? – CBroe
我得到这个错误:'没有'Access-Control-Allow-Origin'标题出现在请求的资源上。原因'http://blah-blah.com'因此不被允许访问。如果一个不透明的响应满足您的需求,请将请求的模式设置为'no-cors'来取消禁用CORS的资源。'如果我设置了'{mode:'no-cors'},它可以正常工作。 – Anthony