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 19:03:24 浏览: 169
这个问题出现的原因是因为浏览器会限制不同源之间的访问,即使是本地文件系统也会受到这种限制。在这种情况下,您需要使用一个本地服务器来提供您的文件,例如使用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:44 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
这是一个跨域请求的错误,由于浏览器的安全策略,不同域名之间的请求是被禁止的。要解决这个问题,需要在服务器端设置CORS(跨域资源共享)策略,允许请求的来源。如果你是使用Java Web开发,可以在响应头中添加Access-Control-Allow-Origin字段,将其值设置为请求的源头。例如,如果你的请求源头是http://localhost:9528,响应头应该包含:Access-Control-Allow-Origin: http://localhost:9528。这样浏览器就会允许跨域请求了。
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.
阅读全文