可在浏览器中无CORS错误调用的示例URL有哪些?
可测试CORS错误的示例域名
当然有,以下几个公开域名在浏览器中发起跨域请求时,必然会触发CORS错误,你可以直接在浏览器控制台测试:
http://example.nethttp://example.orghttp://bbc.co.ukhttp://google.com
这些域名的服务器默认不会返回Access-Control-Allow-Origin响应头,所以当你执行跨域请求时,浏览器会因为同源策略限制,抛出和测试example.com时一致的错误。
比如测试example.net的代码:
fetch('http://example.net').then(console.log).catch(console.error);
执行后你会在控制台看到类似这样的错误提示:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://example.net/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.
TypeError: NetworkError when attempting to fetch resource.
内容的提问来源于stack exchange,提问作者Ooker
相关产品推荐
相关产品推荐

