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 12:03:15 浏览: 99
这个错误提示表明您正在尝试从本地文件系统加载跨域资源,但浏览器不允许跨域请求。解决这个问题的方法是将资源放在同一个域下,或者将资源放在 web 服务器上,通过 http 协议访问。
如果您想在本地环境下使用这些资源,可以考虑使用一个本地服务器来提供您的文件,例如使用 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/,然后您应该能够访问您的本地文件系统并解决跨域问题。
如果您需要在生产环境中使用这些资源,您需要将这些资源放在同一个域下,或者通过 web 服务器提供这些资源。
相关问题
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.
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
这个问题出现的原因是因为浏览器会限制不同源之间的访问,即使是本地文件系统也会受到这种限制。在这种情况下,您需要使用一个本地服务器来提供您的文件,例如使用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问题。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)