Access to XMLHttpRequest at 'file:///C:/Users/Administrator/Desktop/WebSocketClientDemo/AndriodMutilDemo_0521/img/bg.png' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted
时间: 2024-01-03 16:03:24 浏览: 176
这个问题出现的原因是因为浏览器会限制不同源之间的访问,即使是本地文件系统也会受到这种限制。在这种情况下,您需要使用一个本地服务器来提供您的文件,例如使用Node.js中的http-server模块。您可以通过以下步骤解决这个问题:
1. 安装Node.js (https://nodejs.org/en/)
2. 在终端或命令提示符中运行以下命令安装http-server模块:
```
npm install -g http-server
```
3. 在终端或命令提示符中进入您的项目根目录,然后运行以下命令:
```
http-server
```
4. 在浏览器中访问http://localhost:8080/,然后您应该能够访问您的本地文件系统并解决CORS问题。
相关问题
:9528/#/students/index:1 Access to XMLHttpRequest at 'http://localhost:8080/javaWeb_war_exploded/getAllStudents.action' from origin 'http://localhost:9528' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. index.vue?6ced:35 Error: Network Error at createError (webpack-internal:///./node_modules/axios/lib/core/createError.js:16) at XMLHttpRequest.handleError (webpack-internal:///./node_modules/axios/lib/adapters/xhr.js:69) :8080/javaWeb_war_exploded/getAllStudents.action:1 Failed to load resource: net::ERR_FAILED
这是一个关于跨域请求的错误。当一个网站在浏览器中请求另一个域名下的资源时,浏览器会发送一个跨域请求。而出于安全考虑,浏览器会限制跨域请求的访问权限,只有在服务器端配置了相关的跨域访问策略才能正常访问。在这个错误中,服务器端没有配置允许该网站访问的策略,所以浏览器会拒绝访问。需要在服务器端配置相关的策略,或者使用代理等方式来解决。
Access to XMLHttpRequest at 'file:///E:/projects/ThreejsSpace/fbxTest/Angry.fbx'
Access to XMLHttpRequest at 'file:///E:/projects/ThreejsSpace/fbxTest/Angry.fbx is a security feature implemented in web browsers to prevent cross-origin requests. It means that you are trying to make an XMLHttpRequest to a local file on your computer, which is not allowed due to security restrictions.
To access the file 'Angry.fbx' using XMLHttpRequest, you need to host it on a web server and access it through a valid URL. This can be done by setting up a local web server or uploading the file to a remote server.
阅读全文